|
@@ -7,6 +7,7 @@ import cn.hutool.core.util.IdUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import cn.hutool.core.util.ZipUtil;
|
|
|
+import com.aspose.words.Document;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
@@ -19,9 +20,10 @@ import com.rongwei.bscommon.sys.dao.ZhcxOutsideInspectionItpDao;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.rongwei.bsentity.domain.ZhcxOutsideInspectionItpSupervisionDispatchDo;
|
|
|
import com.rongwei.bsentity.dto.NotifyDto;
|
|
|
-import com.rongwei.bsentity.vo.OperOutsideInspectionVo;
|
|
|
-import com.rongwei.bsentity.vo.SupervisionVo;
|
|
|
+import com.rongwei.bsentity.vo.*;
|
|
|
import com.rongwei.commonservice.serial.service.SysSerialNumberService;
|
|
|
+import com.rongwei.rwadmincommon.system.domain.PagePartDo;
|
|
|
+import com.rongwei.rwadmincommon.system.service.PagePartService;
|
|
|
import com.rongwei.rwadmincommon.system.service.SysGeneralCRUDService;
|
|
|
import com.rongwei.rwadmincommon.system.vo.SysUserVo;
|
|
|
import com.rongwei.rwcommon.base.R;
|
|
@@ -30,6 +32,11 @@ import com.rongwei.rwcommon.utils.SecurityUtil;
|
|
|
import com.rongwei.rwcommon.utils.StringUtils;
|
|
|
import com.rongwei.rwcommon.vo.MailDo;
|
|
|
import com.rongwei.rwcommon.vo.generalsql.MasterSlaveUpdateVo;
|
|
|
+import com.rongwei.rwcommoncomponent.excel.aspose.DetailTable;
|
|
|
+import com.rongwei.rwcommoncomponent.excel.aspose.ExcelExportUtil;
|
|
|
+import com.rongwei.rwcommoncomponent.excel.aspose.ExcelFormData;
|
|
|
+import com.rongwei.rwcommoncomponent.excel.aspose.ParseFormParam;
|
|
|
+import com.rongwei.rwcommoncomponent.excel.vo.FormData;
|
|
|
import com.rongwei.rwcommoncomponent.file.service.SysFileItemService;
|
|
|
import com.rongwei.rwcommonentity.commonservers.domain.SysFileItemDo;
|
|
|
import com.rongwei.rwcommonentity.commonservers.vo.SysSerialVo;
|
|
@@ -43,6 +50,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.*;
|
|
|
import java.net.URLEncoder;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
|
|
|
/**
|
|
@@ -83,6 +91,8 @@ public class ZhcxOutsideInspectionItpServiceImpl extends ServiceImpl<ZhcxOutside
|
|
|
|
|
|
@Autowired
|
|
|
private ZhcxOutsideInspectionComponentTrackService inspectionComponentTrackService;
|
|
|
+ @Autowired
|
|
|
+ private PagePartService pagePartService;
|
|
|
|
|
|
@Autowired
|
|
|
private SysNotifyFeginService notifyFeginService;
|
|
@@ -596,12 +606,11 @@ public class ZhcxOutsideInspectionItpServiceImpl extends ServiceImpl<ZhcxOutside
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public int downloadFile(Map<String, Object> map, HttpServletResponse response) throws FileNotFoundException {
|
|
|
- Object itpid = map.get("itpid");
|
|
|
- if(ObjectUtil.isEmpty(itpid)){
|
|
|
+ public int downloadFile(ZhcxOutsideExportVo zhcxOutsideExportVo, HttpServletResponse response) throws FileNotFoundException {
|
|
|
+ String itpId = zhcxOutsideExportVo.getItpid();
|
|
|
+ if(StringUtils.isEmpty(itpId)){
|
|
|
return 0;
|
|
|
}
|
|
|
- String itpId = (String) itpid;
|
|
|
ZhcxOutsideInspectionItpDo inspectionItpDo = getById(itpId);
|
|
|
LambdaQueryWrapper<ZhcxOutsideInspectionItpSupervisionDispatchDo> wrapper = Wrappers.lambdaQuery();
|
|
|
wrapper.eq(ZhcxOutsideInspectionItpSupervisionDispatchDo::getItpid,itpId);
|
|
@@ -621,6 +630,7 @@ public class ZhcxOutsideInspectionItpServiceImpl extends ServiceImpl<ZhcxOutside
|
|
|
if(StringUtils.isNotBlank(files)){
|
|
|
getIds(files, fileIds);
|
|
|
}
|
|
|
+ SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
if(fileIds.size() > 0){
|
|
|
QueryWrapper<SysFileItemDo> qw = new QueryWrapper();
|
|
|
qw.in("ID", fileIds);
|
|
@@ -628,6 +638,7 @@ public class ZhcxOutsideInspectionItpServiceImpl extends ServiceImpl<ZhcxOutside
|
|
|
log.info("下载数据数量:"+list.size());
|
|
|
if(list.size() > 0){
|
|
|
// 获取类路径
|
|
|
+ //String classPath = "/Users/temp";
|
|
|
String classPath = filepath;
|
|
|
// 临时目录 以uuid+时间戳 为目录名称
|
|
|
String temp = classPath +File.separator + IdUtil.simpleUUID() + System.currentTimeMillis();
|
|
@@ -663,11 +674,19 @@ public class ZhcxOutsideInspectionItpServiceImpl extends ServiceImpl<ZhcxOutside
|
|
|
new File(temp+File.separator+filename));
|
|
|
}
|
|
|
);
|
|
|
- // 设置响应的一些格式
|
|
|
+ String format = formatter.format(inspectionItpDo.getReservationinspectiontime());
|
|
|
String fileFullName = inspectionItpDo.getProjectcode()+"-"+inspectionItpDo.getProjectname()+
|
|
|
"-"+inspectionItpDo.getStructurename()+"-"+inspectionItpDo.getInspectioncontent()+
|
|
|
- "-"+inspectionItpDo.getReservationinspectiontime();
|
|
|
- String encodedFileName = URLEncoder.encode(inspectionItpDo.getInspectioncode()+".zip", "UTF-8").replaceAll("\\+", "%20");
|
|
|
+ "-"+format;
|
|
|
+ fileFullName = fileFullName.replaceAll("/","_");
|
|
|
+ ExcelFormData excelData = zhcxOutsideExportVo.getExcelData();
|
|
|
+ excelData.setExcelName(fileFullName+".pdf");
|
|
|
+ SysFileItemDo sysFileItemDo = sysFileItemService.getById(excelData.getTemplateId());
|
|
|
+ FormData formData = parseExcelPage2Data(excelData, sysFileItemDo);
|
|
|
+ parseTemplateByAspose(sysFileItemDo, excelData, temp, formData);
|
|
|
+ // 设置响应的一些格式
|
|
|
+
|
|
|
+ String encodedFileName = URLEncoder.encode(fileFullName+".zip", "UTF-8").replaceAll("\\+", "%20");
|
|
|
response.setContentType("application/octet-stream");
|
|
|
response.setHeader("content-type", "application/octet-stream");
|
|
|
//response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
|
|
@@ -690,7 +709,8 @@ public class ZhcxOutsideInspectionItpServiceImpl extends ServiceImpl<ZhcxOutside
|
|
|
i = bis.read(buffer);
|
|
|
}
|
|
|
} catch (IOException e) {
|
|
|
- throw new RuntimeException(e);
|
|
|
+ e.printStackTrace();
|
|
|
+ log.info("下载压缩资料报错:"+e);
|
|
|
}finally {
|
|
|
if (bis != null) {
|
|
|
try {
|
|
@@ -711,6 +731,7 @@ public class ZhcxOutsideInspectionItpServiceImpl extends ServiceImpl<ZhcxOutside
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
+ log.info("下载资料报错:"+e);
|
|
|
return 1;
|
|
|
}finally {
|
|
|
// 删除临时目录和压缩后的文件
|
|
@@ -726,6 +747,122 @@ public class ZhcxOutsideInspectionItpServiceImpl extends ServiceImpl<ZhcxOutside
|
|
|
return 2;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 将doc文档输出到response中传给前端
|
|
|
+ *
|
|
|
+ * @param response
|
|
|
+ * @param filename
|
|
|
+ * @param doc
|
|
|
+ */
|
|
|
+ private void doc2Response(String tempPath,String filename, Document doc) {
|
|
|
+ try {
|
|
|
+ if (filename.indexOf("直打") >= 0 || filename.toLowerCase().indexOf("pdf") >= 0) {
|
|
|
+ doc.save(tempPath+File.separator+filename, com.aspose.words.SaveOptions.createSaveOptions(com.aspose.words.SaveFormat.PDF));
|
|
|
+ } else {
|
|
|
+ doc.save(tempPath+File.separator+filename, com.aspose.words.SaveOptions.createSaveOptions(com.aspose.words.SaveFormat.DOCX));
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("填充失败:{}", e);
|
|
|
+ throw new CustomException("填充失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void wordTmplPrint(String tempPath,String filename,String templateFilePath, FormData formData)
|
|
|
+ {
|
|
|
+ log.info("准备开始填充 word 模板");
|
|
|
+ Document doc = ExcelExportUtil.fillWordDataByMap(templateFilePath, formData);
|
|
|
+ //doc保存至response
|
|
|
+ doc2Response(tempPath, filename, doc);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * aspose 解析
|
|
|
+ *
|
|
|
+ * @param sysFileItemDo
|
|
|
+ * @param excelData
|
|
|
+ * @param response
|
|
|
+ * @param formData
|
|
|
+ */
|
|
|
+ private void parseTemplateByAspose(SysFileItemDo sysFileItemDo, ExcelFormData excelData, String tempPath, FormData formData) {
|
|
|
+ //word模板导出
|
|
|
+ if(sysFileItemDo.getFiletype().toLowerCase().equals("doc") || sysFileItemDo.getFiletype().toLowerCase().equals("docx")){
|
|
|
+ log.info("word模板导出开始");
|
|
|
+ this.wordTmplPrint(tempPath,excelData.getExcelName(),sysFileItemDo.getFullpath(), formData);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 解析配置获取数据
|
|
|
+ *
|
|
|
+ * @param excelData
|
|
|
+ * @param sysFileItemDo
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private FormData parseExcelPage2Data(ExcelFormData excelData, SysFileItemDo sysFileItemDo) {
|
|
|
+ // 校验许可证
|
|
|
+// ExcelUtils excelUtils = new ExcelUtils();
|
|
|
+ PagePartDo pagePartDo = pagePartService.getById(excelData.getPagepartId());
|
|
|
+ cn.hutool.json.JSONObject pagePartConfig = JSONUtil.parseObj(pagePartDo.getRoption());
|
|
|
+
|
|
|
+ ParseFormParam formParam = ParseFormParam.builder()
|
|
|
+ .formRoption(pagePartConfig)
|
|
|
+ .detailTables(excelData.getDetailTables())
|
|
|
+ .sysFileItemDo(sysFileItemDo)
|
|
|
+ .build();
|
|
|
+
|
|
|
+ return parsePage2Data(excelData.getFormId(), formParam);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 单个表单解析
|
|
|
+ *
|
|
|
+ * @param formId
|
|
|
+ * @param param
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private FormData parsePage2Data(String formId, ParseFormParam param) {
|
|
|
+ //读取主表数据
|
|
|
+ String sqlMain = param.getFormRoption().getByPath("dataSource.formData.mainsql").toString();
|
|
|
+ List<Map<String,Object>> list = sysGeneralCRUDService.getDataBySql("select * from ("+sqlMain+") a where ID= '" + formId + "'");
|
|
|
+ list = ExcelExportUtil.convertFactData(list, param.getFormRoption(), param.getSysFileItemDo());
|
|
|
+ //明细数据
|
|
|
+ ArrayList<List<Map<String,Object>>> listall = new ArrayList<>();
|
|
|
+ //根据配置自动读取明细
|
|
|
+ for (DetailTable detailTable : param.getDetailTables()) {
|
|
|
+
|
|
|
+ if(ObjectUtil.isEmpty(detailTable.getMainRelKey())) {
|
|
|
+ detailTable.setMainRelKey("ID");
|
|
|
+ }
|
|
|
+
|
|
|
+ PagePartDo pagePartDetailDo = pagePartService.getById(detailTable.getPagepartid());
|
|
|
+ cn.hutool.json.JSONObject pagePartConfigDetail = JSONUtil.parseObj(pagePartDetailDo.getRoption());
|
|
|
+ String sqlDetailDetail = pagePartConfigDetail.getByPath("dataSource.formData.mainsql").toString();
|
|
|
+ List<Map<String, Object>> list1 = sysGeneralCRUDService.getDataBySql("select * from (" + sqlDetailDetail + ") a where a.DELETED = '0' and " + detailTable.getRelationid() + "= '" + list.get(0).get(detailTable.getMainRelKey()) + "'");
|
|
|
+
|
|
|
+ // 为了处理aspose-cells模板打印bug,打印前要保证第一索引列有其所有字段,否则打印字段为空
|
|
|
+ // 如果list有多个map,则需要比较其他map中的所有字段
|
|
|
+ List<Map<String, Object>> finalList = list1;
|
|
|
+ if ((finalList.size() > 1)) {
|
|
|
+ for (int i = 1; i < finalList.size(); i++) {
|
|
|
+ finalList.get(i).forEach((k, v)->{
|
|
|
+ // 补上第一索引列缺失的key
|
|
|
+ if (!finalList.get(0).containsKey(k)) {
|
|
|
+ // TODO: 补上的value暂定为字符
|
|
|
+ finalList.get(0).put(k, "");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ list1 = finalList;
|
|
|
+ list1 = ExcelExportUtil.convertFactData(list1, pagePartConfigDetail, param.getSysFileItemDo());
|
|
|
+ listall.add(list1);
|
|
|
+ }
|
|
|
+
|
|
|
+ return FormData.builder()
|
|
|
+ .slaveTableDataList(listall)
|
|
|
+ .mainDataList(list)
|
|
|
+ .build();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
private void getIds(String files, List<String> fileIds) {
|
|
|
String[] split = files.split("\\^_\\^");
|
|
|
for(String fileItem : split){
|