Commit c6adb2a7 by 宋祥

1.批量下载文件

parent 43c7eb17
......@@ -10,11 +10,14 @@ import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ImportResource;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
@EnableScheduling
@SpringBootApplication(scanBasePackages = "com.baosight")
@ServletComponentScan("com.baosight.iplat4j.core.web.servlet")
@ImportResource(locations = {"classpath*:spring/framework/platApplicationContext*.xml","classpath*:spring/framework/applicationContext*.xml"})
@ImportResource(locations = {"classpath*:spring/framework/platApplicationContext*.xml",
"classpath*:spring/framework/applicationContext*.xml"})
@EnableConfigurationProperties({LiquibaseProperties.class, ApplicationProperties.class})
public class HggpApplication extends SpringBootServletInitializer {
......@@ -29,7 +32,7 @@ public class HggpApplication extends SpringBootServletInitializer {
}
@Bean("multipartResolver")
public CommonsMultipartResolver multipartResolver(){
public CommonsMultipartResolver multipartResolver() {
CommonsMultipartResolver resolver = new CommonsMultipartResolver();
resolver.setDefaultEncoding("UTF-8");
resolver.setMaxInMemorySize(10000);
......
......@@ -34,11 +34,16 @@ public class OSConstant {
/**
* 程序运行目录
*/
public final static String DOWN_DIR = USER_DIR + SEPARATOR + "download";
public final static String DOWN_DIR = USER_DIR + SEPARATOR + "file" + SEPARATOR + "download";
/**
* 二维码目录
*/
public final static String QRCODE_DIR = USER_DIR + SEPARATOR + "qrcode";
public final static String QRCODE_DIR = USER_DIR + SEPARATOR + "file" + SEPARATOR + "qrcode";
/**
* 压缩包目录
*/
public final static String ZIP_DIR = USER_DIR + SEPARATOR + "file" + SEPARATOR + "zip";
}
......@@ -22,6 +22,11 @@ public class S3Constant {
public static String ENDPOINT = PlatApplicationContext.getProperty("iplat4j.admin.objectStorage.s3.endpoint");
/**
* resource
*/
public static String RESOURCE = PlatApplicationContext.getProperty("iplat4j.admin.objectStorage.s3.resource");
/**
* bucket名称
*/
public static String BUCKET_NAME = PlatApplicationContext.getProperty("iplat4j.admin.objectStorage.s3.bucket");
......
package com.baosight.hggp.core.utils;
import com.baosight.hggp.core.constant.CommonConstant;
import com.baosight.hggp.core.constant.OSConstant;
import com.baosight.hggp.core.constant.S3Constant;
import com.baosight.hggp.core.tools.Iplat4jTools;
import com.baosight.hggp.util.DateUtils;
import com.baosight.hggp.util.FileUtils;
import com.baosight.hggp.util.MapUtils;
import com.baosight.hggp.util.StringUtils;
......@@ -10,6 +13,7 @@ import com.baosight.iplat4j.core.exception.PlatException;
import com.baosight.iplat4j.core.ioc.spring.PlatApplicationContext;
import com.baosight.iplat4j.eu.dm.util.PlatFileUploader;
import java.util.List;
import java.util.Map;
/**
......@@ -73,4 +77,42 @@ public class Iplat4jUtils {
return document;
}
/**
* 压缩文件
*
* @param docIds
* @param zipName
* @return
*/
public static String compressFile(List<String> docIds, String zipName) throws Exception {
String zipFolderPath = OSConstant.ZIP_DIR + OSConstant.SEPARATOR + DateUtils.shortDate()
+ OSConstant.SEPARATOR + zipName;
FileUtils.createDirs(zipFolderPath);
String zipFilePath = zipFolderPath + ".zip";
if (CommonConstant.FileLocation.S3.equalsIgnoreCase(S3Constant.FILE_LOCATION)) {
for (String docId : docIds) {
Teudm05 dbDm05 = S3Utils.buildUrl(docId);
// 文件路径:压缩包路径+文件名称
String localFilePath = zipFolderPath + OSConstant.SEPARATOR + dbDm05.getResCname();
FileUtils.downloadUrlFile(dbDm05.getUrl(), localFilePath);
}
} else {
for (String docId : docIds) {
Map dbDm02 = Iplat4jUtils.getDoc02ById(docId);
String returnUrl = MapUtils.getString(dbDm02, "url");
String docName = MapUtils.getString(dbDm02, "docName");
// 文件路径:压缩包路径+文件名称
String localFilePath = zipFolderPath + OSConstant.SEPARATOR + docName;
FileUtils.fileCopy(returnUrl, localFilePath);
}
}
// 开始压缩
FileUtils.zip(zipFolderPath, zipFilePath);
// 压缩完删除本地文件
FileUtils.deleteFiles(zipFolderPath);
// 替换成HTTP地址
return S3Constant.RESOURCE + zipFilePath.replace(OSConstant.USER_DIR, "")
.replace(OSConstant.SEPARATOR, "/");
}
}
......@@ -17,6 +17,7 @@ import com.baosight.iplat4j.core.service.impl.ServiceEPBase;
import com.baosight.iplat4j.core.service.soa.XServiceManager;
import org.apache.commons.collections.CollectionUtils;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
......@@ -161,7 +162,7 @@ public class ServiceHGCW999 extends ServiceEPBase {
* @param docId 文件ID
*/
@OperationLogAnnotation(operModul = "附件清单",operType = "删除",operDesc = "删除附件文件")
public void delectDoc(String docId){
public void delectDoc(String docId) throws IOException {
Map<String,Object> map = new HashMap<>();
map.put("docId",docId);
List<HGDS002> list = this.dao.query(HGDS002.QUERY,map);
......
......@@ -14,6 +14,7 @@ import com.baosight.iplat4j.core.exception.PlatException;
import com.baosight.iplat4j.core.service.impl.ServiceEPBase;
import com.baosight.iplat4j.core.service.soa.XServiceManager;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -133,7 +134,7 @@ public class ServiceHGPZ002A extends ServiceEPBase {
* @param docId 文件ID
*/
@OperationLogAnnotation(operModul = "附件清单",operType = "删除",operDesc = "删除附件文件")
public void delectDoc(String docId){
public void delectDoc(String docId) throws IOException {
Map<String,Object> map = new HashMap<>();
map.put("docId",docId);
List<HGDS002> list = this.dao.query(HGDS002.QUERY,map);
......
......@@ -17,6 +17,7 @@ import com.baosight.iplat4j.core.service.impl.ServiceEPBase;
import com.baosight.iplat4j.core.service.soa.XServiceManager;
import com.baosight.iplat4j.core.web.threadlocal.UserSession;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -127,7 +128,7 @@ public class ServiceHGPZ009A extends ServiceEPBase {
* @param docId 文件ID
*/
@OperationLogAnnotation(operModul = "banner清单",operType = "删除",operDesc = "删除附件文件")
public void delectDoc(String docId){
public void delectDoc(String docId) throws IOException {
Map<String,Object> map = new HashMap<>();
map.put("docId",docId);
List<HGDS002> list = this.dao.query(HGDS002.QUERY,map);
......
......@@ -16,6 +16,7 @@ import com.baosight.iplat4j.core.exception.PlatException;
import com.baosight.iplat4j.core.service.impl.ServiceEPBase;
import com.baosight.iplat4j.core.service.soa.XServiceManager;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -96,7 +97,7 @@ public class ServiceHGSB099 extends ServiceEPBase {
* 删除文件
* @param docId 文件ID
*/
public void delectDoc(String docId){
public void delectDoc(String docId) throws IOException {
Map<String,Object> map = new HashMap<>();
map.put("docId",docId);
List<HGDS002> list = this.dao.query(HGDS002.QUERY,map);
......
......@@ -4,18 +4,12 @@ import com.baosight.hggp.aspect.annotation.OperationLogAnnotation;
import com.baosight.hggp.common.ChangeTypeEnum;
import com.baosight.hggp.common.DdynamicEnum;
import com.baosight.hggp.core.constant.CommonConstant;
import com.baosight.hggp.core.dao.DaoBase;
import com.baosight.hggp.core.dao.DaoUtils;
import com.baosight.hggp.core.enums.OrgTypeEnum;
import com.baosight.hggp.core.extapp.decheng.api.DcOpenApi;
import com.baosight.hggp.core.security.UserSessionUtils;
import com.baosight.hggp.core.tools.Iplat4jTools;
import com.baosight.hggp.core.utils.Iplat4jUtils;
import com.baosight.hggp.hg.constant.HGConstant;
import com.baosight.hggp.hg.cw.tools.HGCWTools;
import com.baosight.hggp.hg.dm.tools.HpDmTools;
import com.baosight.hggp.hg.pz.domain.HGPZ009;
import com.baosight.hggp.hg.pz.tools.HGPZTools;
import com.baosight.hggp.hg.sc.domain.HGSC008;
import com.baosight.hggp.hg.wd.constant.HgWdConstant;
import com.baosight.hggp.hg.wd.constant.HgWdSqlConstant;
import com.baosight.hggp.hg.wd.domain.HGWD001;
......@@ -35,9 +29,7 @@ import com.baosight.iplat4j.core.exception.PlatException;
import com.baosight.iplat4j.core.resource.I18nMessages;
import com.baosight.iplat4j.core.service.impl.ServiceEPBase;
import com.baosight.iplat4j.ed.util.SequenceGenerator;
import org.apache.commons.collections.CollectionUtils;
import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;
......@@ -249,6 +241,28 @@ public class ServiceHGWD001 extends ServiceEPBase {
return inInfo;
}
private static void cleanBaseInfo(HGWD099 hgwd099) {
hgwd099.setCreatedBy(null);
hgwd099.setCreatedName(null);
hgwd099.setCreatedTime(null);
hgwd099.setUpdatedBy(null);
hgwd099.setUpdatedName(null);
hgwd099.setUpdatedTime(null);
hgwd099.setDepCode(null);
hgwd099.setId(null);
}
private static void cleanBaseInfo(HGWD001 hgwd001) {
hgwd001.setCreatedBy(null);
hgwd001.setCreatedName(null);
hgwd001.setCreatedTime(null);
hgwd001.setUpdatedBy(null);
hgwd001.setUpdatedName(null);
hgwd001.setUpdatedTime(null);
hgwd001.setDepCode(null);
hgwd001.setId(null);
}
@OperationLogAnnotation(operModul = "文档库",operType = "修改",operDesc = "文档库-附件变更-变更附件操作")
public EiInfo updateFile(EiInfo inInfo) {
try {
......@@ -290,7 +304,8 @@ public class ServiceHGWD001 extends ServiceEPBase {
List<String> userIds = listByFile.stream().filter(item -> !item.getUserId().equals(UserSessionUtils.getUserId()))
.map(HGWD003::getExtId)
.filter(ObjectUtils::isNotBlank).distinct().collect(Collectors.toList());
HGWDTools.interaction(String.format("[%s]项目变更附件通知",hgwd001.getProjName()),strFileName.substring(0,strFileName.length()-1),userIds);
HGWDTools.interaction(String.format("[%s]项目变更附件通知", hgwd001.getProjName()),
strFileName.substring(0, strFileName.length() - 1), userIds);
inInfo.setStatus(EiConstant.STATUS_DEFAULT);
inInfo.setMsg("操作成功!本次对[" + resultRows.size() + "]条数据新增成功!");
} catch (Exception e) {
......@@ -301,12 +316,13 @@ public class ServiceHGWD001 extends ServiceEPBase {
/**
* 初始化变更记录
*
* @param hgwd001 项目信息
* @param hgwd099 附件信息
* @param type 变更类型
* @return HGWD001A 变更记录
*/
public HGWD001A initHgwd001a(HGWD001 hgwd001,HGWD099 hgwd099,String type){
public HGWD001A initHgwd001a(HGWD001 hgwd001, HGWD099 hgwd099, String type) {
HGWD001A hgwd001a = new HGWD001A();
hgwd001a.setCompanyCode(hgwd001.getCompanyCode());
hgwd001a.setCompanyName(hgwd001.getCompanyName());
......@@ -316,15 +332,15 @@ public class ServiceHGWD001 extends ServiceEPBase {
hgwd001a.setChangeType(ChangeTypeEnum.UPLOAD_ADD.getCode());
}else if (ChangeTypeEnum.DELETE.getCode().equals(type)){
hgwd001a.setChangeType(ChangeTypeEnum.UPLOAD_DELETE.getCode());
}else if (ChangeTypeEnum.UPLOAD_UPDATE.getCode().equals(type)){
} else if (ChangeTypeEnum.UPLOAD_UPDATE.getCode().equals(type)) {
hgwd001a.setChangeType(ChangeTypeEnum.UPLOAD_UPDATE.getCode());
hgwd001a.setChangeStartCode(hgwd099.getDocId());
hgwd001a.setChangeStart(hgwd099.getDocName());
}else if (ChangeTypeEnum.RELEASE.getCode().equals(type)){
} else if (ChangeTypeEnum.RELEASE.getCode().equals(type)) {
hgwd001a.setChangeType(ChangeTypeEnum.RELEASE.getCode());
hgwd001a.setChangeContent(hgwd001.getRemark().trim().length()==0?"附件发布":hgwd001.getRemark().trim());
hgwd001a.setChangeStart("V".concat(hgwd001.getDocVersion()+""));
hgwd001a.setChangeEnd("V".concat(hgwd001.getDocVersion()+1+""));
hgwd001a.setChangeContent(hgwd001.getRemark().trim().length() == 0 ? "附件发布" : hgwd001.getRemark().trim());
hgwd001a.setChangeStart("V".concat(hgwd001.getDocVersion() + ""));
hgwd001a.setChangeEnd("V".concat(hgwd001.getDocVersion() + 1 + ""));
}
hgwd001a.setChangeContent(hgwd001.getFileName());
hgwd001a.setMatId(hgwd001.getId());
......@@ -354,7 +370,7 @@ public class ServiceHGWD001 extends ServiceEPBase {
this.dao.update(HGWD001.DELETE, idMap);
Map memberMap = new HashMap();
memberMap.put(HGWD099.FIELD_BIZ_ID, ((Map) orgIdChildList.get(j)).get("fileId"));
DaoUtils.update("HGWD099.deleteBizId",memberMap); //删除附件记录
DaoUtils.update("HGWD099.deleteBizId", memberMap); //删除附件记录
++sum;
}
}
......@@ -367,7 +383,7 @@ public class ServiceHGWD001 extends ServiceEPBase {
public EiInfo query1(EiInfo inInfo) {
try {
Map queryRow =EiInfoUtils.getFirstRow(inInfo, "inqu_status1");
Map queryRow = EiInfoUtils.getFirstRow(inInfo, "inqu_status1");
queryRow.put(HGWD001.FIELD_DELETE_FLAG, CommonConstant.YesNo.NO_0);
// 非管理员仅查询自己有权限的项目
String userId = UserSessionUtils.getLoginName();
......@@ -378,21 +394,22 @@ public class ServiceHGWD001 extends ServiceEPBase {
block.addRow(queryRow);
inInfo.setBlock(block);
return super.query(inInfo, HGWD001.QUERY, new HGWD001(), false, new HGWD001().eiMetadata, "inqu_status1","result1","result1",null);
return super.query(inInfo, HGWD001.QUERY, new HGWD001(), false, new HGWD001().eiMetadata, "inqu_status1",
"result1", "result1", null);
} catch (Exception e) {
LogUtils.setMsg(inInfo, e, "查询失败");
}
return inInfo;
}
@OperationLogAnnotation(operModul = "文档库",operType = "复制附件",operDesc = "文档库-附件复制-附件复制操作")
@OperationLogAnnotation(operModul = "文档库", operType = "复制附件", operDesc = "文档库-附件复制-附件复制操作")
public EiInfo save1(EiInfo inInfo) {
try {
List<Map> resultRows = inInfo.getBlock(EiConstant.resultBlock).getRows();
List<Map> result1Rows = inInfo.getBlock("result1").getRows();
//List<Map<String, Object>> edcm01List = Iplat4jTools.EdCm01.list("hggp.hgwd.fileType");
// 写入数据
for (Map result1Row:result1Rows) {
for (Map result1Row : result1Rows) {
StringBuilder strFileName = new StringBuilder();
HGWD001 hgwd001 = new HGWD001();
hgwd001.fromMap(result1Row);
......@@ -407,7 +424,7 @@ public class ServiceHGWD001 extends ServiceEPBase {
DaoUtils.insert(HGWD099.INSERT, hgdm099);
strFileName.append(hgdm099.getDocName()).append(",");
HGWD001A hgwd001a =initHgwd001a(hgwd001, hgdm099,ChangeTypeEnum.UPLOAD_ADD.getCode());
HGWD001A hgwd001a = initHgwd001a(hgwd001, hgdm099, ChangeTypeEnum.UPLOAD_ADD.getCode());
hgwd001a.setChangeEndCode(hgdm099.getDocId());
hgwd001a.setChangeEnd(hgdm099.getDocName());
HGWDTools.HgWd001.addHGWD001A(hgwd001a);
......@@ -427,12 +444,13 @@ public class ServiceHGWD001 extends ServiceEPBase {
/**
* 复制项目列表
*
* @param inInfo
* @return
*/
public EiInfo query2(EiInfo inInfo) {
try {
Map queryRow =EiInfoUtils.getFirstRow(inInfo, "inqu_status2");
Map queryRow = EiInfoUtils.getFirstRow(inInfo, "inqu_status2");
queryRow.put(HGWD001.FIELD_DELETE_FLAG, CommonConstant.YesNo.NO_0);
// 非管理员仅查询自己有权限的项目
String userId = UserSessionUtils.getLoginName();
......@@ -442,26 +460,29 @@ public class ServiceHGWD001 extends ServiceEPBase {
EiBlock block = inInfo.getBlock(EiConstant.queryBlock);
block.addRow(queryRow);
inInfo.setBlock(block);
return super.query(inInfo, HGWD001.QUERY, new HGWD001(), false, new HGWD001().eiMetadata, "inqu_status2","result2","result2",null);
return super.query(inInfo, HGWD001.QUERY, new HGWD001(), false, new HGWD001().eiMetadata, "inqu_status2",
"result2", "result2", null);
} catch (Exception e) {
LogUtils.setMsg(inInfo, e, "查询失败");
}
return inInfo;
}
@OperationLogAnnotation(operModul = "文档库",operType = "复制项目",operDesc = "文档库-复制项目-复制项目操作")
@OperationLogAnnotation(operModul = "文档库", operType = "复制项目", operDesc = "文档库-复制项目-复制项目操作")
public EiInfo save2(EiInfo inInfo) {
try {
Map<String,String> queryMap= EiInfoUtils.getFirstRow(inInfo,EiConstant.queryBlock);
Map<String, String> queryMap = EiInfoUtils.getFirstRow(inInfo, EiConstant.queryBlock);
List<HGWD001> result1Rows = MapUtils.toDaoEPBases(inInfo.getBlock("result2").getRows(), HGWD001.class);
List<HGWD001> hgwd001List = HGWDTools.HgWd001.queryByParentId(queryMap.get(HGWD001.FIELD_PROJ_CODE),queryMap.get(HGWD001.FIELD_PARENT_ID));
if (queryMap.get("leafType").equals(HgWdConstant.LeafType.P)){
hgwd001List = HGWDTools.HgWd001.queryByProjCode(queryMap.get(HGWD001.FIELD_PROJ_CODE),queryMap.get(HGWD001.FIELD_PARENT_ID));
List<HGWD001> hgwd001List = HGWDTools.HgWd001.queryByParentId(queryMap.get(HGWD001.FIELD_PROJ_CODE),
queryMap.get(HGWD001.FIELD_PARENT_ID));
if (queryMap.get("leafType").equals(HgWdConstant.LeafType.P)) {
hgwd001List = HGWDTools.HgWd001.queryByProjCode(queryMap.get(HGWD001.FIELD_PROJ_CODE),
queryMap.get(HGWD001.FIELD_PARENT_ID));
}
// 要复制项目
String parentId = result1Rows.get(0).getParentId();
if (!StringUtils.isNull(hgwd001List)){
if (!StringUtils.isNull(hgwd001List)) {
hgwd001List.forEach(hgwd001 -> {
hgwd001.setParentId(parentId);
});
......@@ -477,14 +498,14 @@ public class ServiceHGWD001 extends ServiceEPBase {
return inInfo;
}
public void addNode(List<HGWD001> hgwd001List){
public void addNode(List<HGWD001> hgwd001List) {
List<String> fileIds = hgwd001List.stream().map(HGWD001::getFileId).collect(Collectors.toList());
List<HGWD001> hgwd001s = HGWDTools.HgWd001.listByParentIds(fileIds);
for (HGWD001 hgwd001:hgwd001List) {
for (HGWD001 hgwd001 : hgwd001List) {
String fileId = SequenceGenerator.getNextSequence(HGConstant.SequenceId.WD_FILE_ID);
if (!StringUtils.isNull(hgwd001s)){
if (!StringUtils.isNull(hgwd001s)) {
hgwd001s.forEach(o -> {
if (o.getParentId().equals(hgwd001.getFileId())){
if (o.getParentId().equals(hgwd001.getFileId())) {
o.setParentId(fileId);
}
});
......@@ -492,18 +513,19 @@ public class ServiceHGWD001 extends ServiceEPBase {
addCopyFile(hgwd001, fileId);
}
if (hgwd001s != null && hgwd001s.size() > 0){
if (hgwd001s != null && hgwd001s.size() > 0) {
addNode(hgwd001s);
}
}
private void addCopyFile(HGWD001 hgwd001, String fileId){
private void addCopyFile(HGWD001 hgwd001, String fileId) {
List<HGWD099> hgwd099List = HGWDTools.HgWd099.queryByBiz("WD", hgwd001.getFileId());
StringBuilder strFileName = new StringBuilder();
strFileName.append(hgwd001.getFileName()).append("上传附件:附件名称");
List<HGWD099> hgwd099s = hgwd099List.stream().filter(hgdm099 -> hgdm099.getBizId().equals(hgwd001.getFileId())).collect(Collectors.toList());
List<HGWD099> hgwd099s = hgwd099List.stream().filter(hgdm099 -> hgdm099.getBizId().equals(hgwd001.getFileId()))
.collect(Collectors.toList());
for (HGWD099 hgwd099 : hgwd099s) {
cleanBaseInfo(hgwd099);
hgwd099.setDeleteFlag(CommonConstant.YesNo.NO_0);
......@@ -512,7 +534,7 @@ public class ServiceHGWD001 extends ServiceEPBase {
DaoUtils.insert(HGWD099.INSERT, hgwd099);
strFileName.append(hgwd099.getDocName()).append(",");
HGWD001A hgwd001a =initHgwd001a(hgwd001, hgwd099,ChangeTypeEnum.UPLOAD_ADD.getCode());
HGWD001A hgwd001a = initHgwd001a(hgwd001, hgwd099, ChangeTypeEnum.UPLOAD_ADD.getCode());
hgwd001a.setChangeEndCode(hgwd099.getDocId());
hgwd001a.setChangeEnd(hgwd099.getDocName());
HGWDTools.HgWd001.addHGWD001A(hgwd001a);
......@@ -528,34 +550,32 @@ public class ServiceHGWD001 extends ServiceEPBase {
public EiInfo queryProjectManager(EiInfo inInfo) {
try {
Map queryRow =EiInfoUtils.getFirstRow(inInfo);
Integer isManager =HGWDTools.HgWd003.isProjectManager(queryRow.get(HGWD001.FIELD_FILE_ID).toString());
Map queryRow = EiInfoUtils.getFirstRow(inInfo);
Integer isManager = HGWDTools.HgWd003.isProjectManager(queryRow.get(HGWD001.FIELD_FILE_ID).toString());
inInfo.set("isManager", isManager);
}catch (Exception e){
} catch (Exception e) {
LogUtils.setMsg(inInfo, e, "查询失败");
}
return inInfo;
}
private static void cleanBaseInfo(HGWD099 hgwd099){
hgwd099.setCreatedBy(null);
hgwd099.setCreatedName(null);
hgwd099.setCreatedTime(null);
hgwd099.setUpdatedBy(null);
hgwd099.setUpdatedName(null);
hgwd099.setUpdatedTime(null);
hgwd099.setDepCode(null);
hgwd099.setId(null);
/**
* 批量下载
*
* @param inInfo
* @return
*/
public EiInfo batchDownload(EiInfo inInfo) {
try {
Map queryMap = EiInfoUtils.getFirstRow(inInfo);
String fileName = MapUtils.getString(queryMap, HGWD001.FIELD_FILE_NAME);
String zipName = fileName + "_" + DateUtils.shortDateTime();
List<String> docIds = ObjectUtils.listKey(inInfo, HGWD099.FIELD_DOC_ID);
inInfo.set("downloadUrl", Iplat4jUtils.compressFile(docIds, zipName));
} catch (Exception e) {
LogUtils.setMsg(inInfo, e, "批量下载失败");
}
private static void cleanBaseInfo(HGWD001 hgwd001){
hgwd001.setCreatedBy(null);
hgwd001.setCreatedName(null);
hgwd001.setCreatedTime(null);
hgwd001.setUpdatedBy(null);
hgwd001.setUpdatedName(null);
hgwd001.setUpdatedTime(null);
hgwd001.setDepCode(null);
hgwd001.setId(null);
return inInfo;
}
}
......@@ -14,6 +14,7 @@ import com.baosight.iplat4j.core.exception.PlatException;
import com.baosight.iplat4j.core.service.impl.ServiceEPBase;
import com.baosight.iplat4j.core.service.soa.XServiceManager;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -115,7 +116,7 @@ public class ServiceHGXT099 extends ServiceEPBase {
* @param docId 文件ID
*/
@OperationLogAnnotation(operModul = "附件清单",operType = "删除",operDesc = "删除附件文件")
public void delectDoc(String docId){
public void delectDoc(String docId) throws IOException {
Map<String,Object> map = new HashMap<>();
map.put("docId",docId);
List<HGDS002> list = this.dao.query(HGDS002.QUERY,map);
......
package com.baosight.hggp.job;
import com.baosight.hggp.core.constant.OSConstant;
import com.baosight.hggp.util.DateUtil;
import com.baosight.hggp.util.DateUtils;
import com.baosight.hggp.util.FileUtils;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.io.File;
import java.time.LocalDate;
import lombok.extern.slf4j.Slf4j;
/**
* @author:songx
* @date:2024/10/11,12:26
*/
@Slf4j
@Component
public class ClearZipJob {
/**
* 清理ZIP文件
*/
@Scheduled(cron = "0 15 3 * * ?")
public void clearZipFile() {
try {
File zipFolder = new File(OSConstant.ZIP_DIR);
File[] zipFolderFiles = zipFolder.listFiles();
if (zipFolderFiles.length == 0) {
log.warn("清理ZIP文件:无有效的文件");
}
for (File zipFolderFile : zipFolderFiles) {
String folderName = zipFolderFile.getName();
// 当天以前的文件夹全部删除
if (LocalDate.parse(folderName, DateUtils.SHORT_DATE).isBefore(LocalDate.now())) {
FileUtils.deleteFiles(zipFolderFile);
}
}
log.info("清理ZIP文件成功!!!");
} catch (Exception e) {
log.error("清理ZIP文件失败:{}", e.getMessage(), e);
}
}
}
......@@ -2,6 +2,8 @@ package com.baosight.hggp.util;
import com.baosight.hggp.core.constant.OSConstant;
import org.apache.poi.util.IOUtils;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
......@@ -18,9 +20,12 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.DecimalFormat;
import java.time.LocalDateTime;
......@@ -30,6 +35,8 @@ import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import lombok.extern.slf4j.Slf4j;
......@@ -187,6 +194,40 @@ public class FileUtils extends org.apache.commons.io.FileUtils {
/**
* 删除目录及文件
*
* @param path
* @return
*/
public static boolean deleteFiles(String path) {
return deleteFiles(Paths.get(path));
}
/**
* 删除目录及文件
*
* @param path
* @return
*/
public static boolean deleteFiles(Path path) {
try {
if (Files.isDirectory(path)) {
try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(path)) {
for (Path entry : directoryStream) {
deleteFiles(entry);
}
} catch (Exception e) {
log.error("删除文件失败,读取目录子文件失败:{}", e.getMessage(), e);
}
}
} catch (Exception e) {
log.error("删除文件失败:{}", e.getMessage(), e);
return false;
}
return deleteFile(path);
}
/**
* 删除目录及文件
*
* @param file
* @return
*/
......@@ -214,7 +255,25 @@ public class FileUtils extends org.apache.commons.io.FileUtils {
public static boolean deleteFile(String path) {
Objects.requireNonNull(path);
// 路径为文件且不为空则进行删除
return deleteFile(new File(path));
return deleteFile(Paths.get(path));
}
/**
* 删除单个文件或目录
*
* @param path 被删除的文件
* @return
*/
public static boolean deleteFile(Path path) {
Objects.requireNonNull(path);
// 路径为文件且不为空则进行删除
try {
Files.delete(path);
} catch (Exception e) {
log.error("删除文件失败:{}", e.getMessage(), e);
return false;
}
return true;
}
/**
......@@ -266,43 +325,20 @@ public class FileUtils extends org.apache.commons.io.FileUtils {
* @param targetPath
* @throws IOException
*/
public static void fileCope(String filePath, String targetPath) throws IOException {
// 获得流
FileInputStream fileInputStream = null;
//新文件输出流
FileOutputStream fileOutputStream = null;
try {
fileInputStream = new FileInputStream(filePath);
public static void fileCopy(String filePath, String targetPath) throws IOException {
File targetFile = new File(targetPath);
//获取父目录
File parentFile = targetFile.getParentFile();
//判断是否存在
if (!parentFile.exists()) {
// 创建父目录文件夹
parentFile.mkdirs();
}
//判断文件是否存在
if (!targetFile.exists()) {
//创建文件
targetFile.createNewFile();
}
fileOutputStream = new FileOutputStream(targetFile);
creatFiles(targetPath);
try (FileInputStream fis = new FileInputStream(filePath);
FileOutputStream fos = new FileOutputStream(targetFile)) {
byte[] buffer = new byte[1024];
int len;
//将文件流信息读取文件缓存区,如果读取结果不为-1就代表文件没有读取完毕,反之已经读取完毕
while ((len = fileInputStream.read(buffer)) != -1) {
fileOutputStream.write(buffer, 0, len);
fileOutputStream.flush();
while ((len = fis.read(buffer)) != -1) {
fos.write(buffer, 0, len);
fos.flush();
}
} catch (Exception e) {
throw e;
} finally {
if (fileInputStream != null) {
fileInputStream.close();
}
if (fileOutputStream != null) {
fileOutputStream.close();
}
}
}
......@@ -464,16 +500,6 @@ public class FileUtils extends org.apache.commons.io.FileUtils {
}
/**
* InputStream
*
* @param url
*/
public static InputStream downloadStreamFromUrl(String url) throws IOException {
URL httpUrl = new URL(url);
return httpUrl.openStream();
}
/**
* 文件下载
*
* @param file
......@@ -491,18 +517,48 @@ public class FileUtils extends org.apache.commons.io.FileUtils {
}
/**
* 下载文件到本地
*
* @param httpUrl
* @param localFilePath
*/
public static void downloadUrlFile(String httpUrl, String localFilePath) throws IOException {
// 创建文件
FileUtils.creatFiles(localFilePath);
URL url = new URL(httpUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
try (InputStream is = connection.getInputStream();
OutputStream os = new FileOutputStream(localFilePath)) {
// 这里也很关键每次读取的大小为5M,不一次性读取完
byte[] buffer = new byte[1024 * 1024 * 1];
int len = 0;
while ((len = is.read(buffer)) != -1) {
os.write(buffer, 0, len);
}
} catch (IOException e) {
throw e;
} finally {
connection.disconnect();
}
}
/**
* 下载文件到前端
*
* @param url
* @param httpUrl
* @param fileName
* @param response
*/
public static void downloadUrlFile(String url, String fileName, boolean isPreview, HttpServletResponse response)
public static void downloadUrlFile(String httpUrl, String fileName, boolean isPreview, HttpServletResponse response)
throws IOException {
try (InputStream is = downloadStreamFromUrl(url);) {
URL url = new URL(httpUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
try (InputStream is = connection.getInputStream()) {
downloadFile(is, fileName, isPreview, response);
} catch (Exception e) {
throw e;
} finally {
connection.disconnect();
}
}
......@@ -572,4 +628,41 @@ public class FileUtils extends org.apache.commons.io.FileUtils {
}
}
/**
* 压缩文件夹.
*
* @param sourceFilePath 源文件夹路径
* @param zipFilePath 压缩包路径
*/
public static void zip(String sourceFilePath, String zipFilePath) throws IOException {
File zipFile = new File(zipFilePath);
if (zipFile.exists()) {
zipFile.delete();
}
try (FileOutputStream fos = new FileOutputStream(zipFile);
ZipOutputStream zos = new ZipOutputStream(fos)) {
File[] sourceFiles = new File(sourceFilePath).listFiles();
if (null == sourceFiles || sourceFiles.length < 1) {
log.info("待压缩的文件目录:" + sourceFilePath + "里面不存在文件,无需压缩.");
}
byte[] buffs = new byte[1024 * 10];
for (File sourceFile : sourceFiles) {
// 创建ZIP实体,并添加进压缩包
ZipEntry zipEntry = new ZipEntry(sourceFile.getName());
zos.putNextEntry(zipEntry);
// 读取待压缩的文件并写进压缩包里
try (FileInputStream fis = new FileInputStream(sourceFile);
BufferedInputStream bis = new BufferedInputStream(fis, 1024 * 10)) {
int read = 0;
while ((read = bis.read(buffs, 0, 1024 * 10)) != -1) {
zos.write(buffs, 0, read);
}
} catch (IOException e) {
throw e;
}
}
} catch (IOException e) {
throw e;
}
}
}
package com.baosight.hggp.util;
import com.baosight.iplat4j.core.data.DaoEPBase;
import com.baosight.iplat4j.core.ei.EiConstant;
import com.baosight.iplat4j.core.ei.EiInfo;
import org.apache.commons.collections.CollectionUtils;
import java.util.Collection;
......@@ -109,6 +111,22 @@ public class ObjectUtils extends org.apache.commons.lang.ObjectUtils {
/**
* 从集合MAP中取KEY
*
* @param inInfo
* @param keyName
* @return
*/
public static <T> List<T> listKey(EiInfo inInfo, String keyName) {
List<Map> items = inInfo.getBlock(EiConstant.resultBlock).getRows();
if (CollectionUtils.isEmpty(items)) {
return null;
}
return items.stream().map(item -> (T) item.get(keyName)).filter(ObjectUtils::isNotBlank).distinct()
.collect(Collectors.toList());
}
/**
* 从集合MAP中取KEY
*
* @param items
* @param keyName
* @return
......
......@@ -469,9 +469,9 @@ $(function () {
readonly: true,
template: function (item) {
let template = '<a style="cursor: pointer;display: inline-flex;justify-content: center;margin:auto 5px" '
+ 'href="' + downloadHref(item.docId) + '">附件下载</a>';
+ 'href="' + downloadHref(item.docId) + '">下载</a>';
template += '<a style="cursor: pointer;display: inline-flex;justify-content: center;margin:auto 5px" '
+ 'onclick="changeFile(\'' + item.docId + '\',\''+item.bizId+'\')" target="_blank">附件变更</a>';
+ 'onclick="changeFile(\'' + item.docId + '\',\''+item.bizId+'\')" target="_blank">变更</a>';
return template;
}
}, {
......@@ -506,6 +506,8 @@ $(function () {
$("#SAVE2").on("click", saveProtFunc);
//确认发布
$("#confirmRelease").on("click", updateRelease);
// 批量下载
$("#BATCH_DOWNLOAD").on("click", batchDownload);
});
let query = function () {
......@@ -1003,3 +1005,21 @@ let isProjectManager = function (parentId) {
async: false
})
}
/**
* 批量下载
*/
let batchDownload = function () {
var rows = resultGrid.getCheckedRows();
if (rows.length == 0) {
message("请先勾选要下载的数据!");
return;
}
JSUtils.submitGridsData("result", "HGWD001", "batchDownload", false,
function (res) {
if (res.status > -1) {
window.open(res.extAttr.downloadUrl, '_blank');
}
}
);
}
......@@ -71,7 +71,7 @@
serviceName="HGWD099" queryMethod="query" deleteMethod="delete">
<EF:EFColumn ename="id" cname="ID" hidden="true"/>
<EF:EFColumn ename="docId" cname="文件ID" enable="false" width="180" hidden="true"/>
<EF:EFColumn ename="operator" cname="操作" enable="false" width="140" align="center" sort="false"/>
<EF:EFColumn ename="operator" cname="操作" enable="false" width="100" align="center" sort="false"/>
<EF:EFColumn ename="docName" cname="文件名称" enable="false" width="180"/>
<EF:EFColumn ename="docType" cname="文件类型" enable="false" width="110" align="center"/>
<EF:EFColumn ename="docVersion" cname="版本号" enable="false" width="90" align="center" sort="true"/>
......
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