diff --git a/aiyh/utils/Util.java b/aiyh/utils/Util.java index 8805f19..d038b5f 100644 --- a/aiyh/utils/Util.java +++ b/aiyh/utils/Util.java @@ -15,6 +15,7 @@ import aiyh.utils.sqlUtil.whereUtil.impl.WhereImpl; import aiyh.utils.zwl.common.ToolUtil; import cn.hutool.core.util.ObjectUtil; import com.ibm.icu.text.SimpleDateFormat; +import org.h2.util.StringUtils; import weaver.common.util.string.StringUtil; import weaver.conn.RecordSet; import weaver.general.GCONST; @@ -1353,4 +1354,40 @@ public class Util extends weaver.general.Util { return rs.getString(1); } + + /** + * 根据流程和流程字段查询文档目录 + * @param workflowId + * @param docField + * @return + */ + public static String getDocCategorys(String workflowId,String docField){ + RecordSet rs = new RecordSet(); + rs.executeQuery("select formid from workflow_base where id = ?",workflowId); + String formId = Util.recordeSet2Entity(rs, String.class); + String query = "select doccategory from workflow_fileupload where fieldid = (select id from workflow_billfield where fieldname = ? and billid = ?)"; + rs.executeQuery(query,docField,formId); + String docCategorys =Util.null2String(Util.recordeSet2Entity(rs, String.class)); + if(StringUtils.isNullOrEmpty(docCategorys)){ + query = "select doccategory from workflow_base where id = ?"; + rs.executeQuery(query,workflowId); + rs.next(); + docCategorys = Util.null2String(rs.getString(1)); + } + if(StringUtils.isNullOrEmpty(docCategorys)){ + docCategorys = ",,1"; + } + return docCategorys; + } + + public static String null2DefaultStr(Object obj, String defaultStr){ + String objStr = Util.null2String(obj); + if(StringUtils.isNullOrEmpty(objStr) && StringUtils.isNullOrEmpty(defaultStr)){ + return ""; + } + if(StringUtils.isNullOrEmpty(objStr) && !StringUtils.isNullOrEmpty(defaultStr)){ + return defaultStr; + } + return ""; + } } diff --git a/com/api/aiyh_kafang/service/InvoiceService.java b/com/api/aiyh_kafang/service/InvoiceService.java index e18fb48..423a9e3 100644 --- a/com/api/aiyh_kafang/service/InvoiceService.java +++ b/com/api/aiyh_kafang/service/InvoiceService.java @@ -19,6 +19,9 @@ import weaver.formmode.data.ModeDataIdUpdate; import weaver.formmode.setup.ModeRightInfo; import weaver.hrm.User; +import javax.imageio.ImageIO; +import java.awt.image.BufferedImage; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.util.*; @@ -58,12 +61,30 @@ public class InvoiceService { * @throws IOException */ public JSONObject getInvoiceInfo(User user, int fileId) throws Exception { -// InputStream inputStreamById = ImageFileManager.getInputStreamById(fileId); -// byte[] bytes; -// bytes = IOUtils.toByteArray(inputStreamById); - String fileData = FnaInvoiceUploadUtil.changeFileTobase64(fileId); +// 方法一 +/* InputStream inputStreamById = ImageFileManager.getInputStreamById(fileId); + byte[] bytes; + bytes = IOUtils.toByteArray(inputStreamById); + JSONObject jsonObject = HttpUtil.postImage(bytes, user);*/ + +// 方法二 +/* String fileData = FnaInvoiceUploadUtil.changeFileTobase64(fileId); byte[] imageBytes = ImageUtil.transformImage(fileData); - JSONObject jsonObject = HttpUtil.postImage(imageBytes, user); + JSONObject jsonObject = HttpUtil.postImage(imageBytes, user);*/ + + +// 方法三 + InputStream inputStreamById = ImageFileManager.getInputStreamById(fileId); + BufferedImage imageBuffer = ImageIO.read(inputStreamById); + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + boolean jpeg = ImageIO.write(imageBuffer, "jpeg", byteArrayOutputStream); + if(!jpeg){ + toolUtil.writeErrorLog("图片转化转化失败!"); + } + byte[] bytes = byteArrayOutputStream.toByteArray(); + JSONObject jsonObject = HttpUtil.postImage(bytes, user); + + toolUtil.writeErrorLog(jsonObject.toString()); return jsonObject; } diff --git a/customization/test/CopyFileTest.java b/customization/test/CopyFileTest.java index ab1a5f7..9cbb3df 100644 --- a/customization/test/CopyFileTest.java +++ b/customization/test/CopyFileTest.java @@ -7,6 +7,8 @@ import com.api.aiyh_pcn.copy_attachment.dao.ConfigTableData; import com.api.aiyh_pcn.copy_attachment.model.ConfigEmpty; import com.api.aiyh_pcn.copy_attachment.web.CopyAttachment; import org.junit.Test; +import weaver.docs.docs.seconddev.CreateDocForJSGJXT; +import weaver.docs.pdf.docpreview.ConvertMultiPdfTools; import java.io.IOException; import java.util.HashMap; @@ -46,4 +48,17 @@ public class CopyFileTest extends BaseTest{ TestVo testVo = new TestVo(); System.out.println(testVo); } + + + @Test + public void testInvoice(){ + + } + + @Test + public void testPdf(){ +// ConvertMultiPdfTools convertMultiPdfTools = new ConvertMultiPdfTools(); + CreateDocForJSGJXT createDocForJSGJXT = new CreateDocForJSGJXT(); + int fileName = createDocForJSGJXT.creatDoc(null, "fileName", 8, "1,2,3"); + } } diff --git a/customization/test/NewTest.java b/customization/test/NewTest.java index 7d8a461..1e0ee12 100644 --- a/customization/test/NewTest.java +++ b/customization/test/NewTest.java @@ -474,6 +474,13 @@ public class NewTest extends BaseTest { out.close(); } + + @Test + public void testDocCategorys(){ + String docCategorys = Util.getDocCategorys("47","khpj"); + System.out.println(docCategorys); + } + } diff --git a/weaver/aiyh_pcn/convert_pdf/ConvertPdfAction.java b/weaver/aiyh_pcn/convert_pdf/ConvertPdfAction.java new file mode 100644 index 0000000..4d58f71 --- /dev/null +++ b/weaver/aiyh_pcn/convert_pdf/ConvertPdfAction.java @@ -0,0 +1,159 @@ +package weaver.aiyh_pcn.convert_pdf; + +import aiyh.utils.Util; +import aiyh.utils.mapUtil.ParaMap; +import aiyh.utils.sqlUtil.sqlResult.impl.PrepSqlResultImpl; +import aiyh.utils.zwl.common.ToolUtil; +import org.h2.util.StringUtils; +import weaver.conn.RecordSet; +import weaver.docs.docs.seconddev.CreateDocForJSGJXT; +import weaver.hrm.User; +import weaver.interfaces.workflow.action.Action; +import weaver.soa.workflow.request.RequestInfo; + +import java.util.Map; + +/** + * @author EBU7-dev1-ayh + * @create 2021/11/15 0015 14:38 + * PDF 合并action + */ + + +public class ConvertPdfAction implements Action { + +// 需要合并的字段 + private String mergeField; +// 合并后存放文件的字段 + private String mergeToField; +// 1.流程字段,2,action参数,3流程字段+action参数,4 流程多字段拼接 + private String mergePDFNameType; +// action参数的文件名 + private String mergePDFName; +// 流程字段和多字段 + private String mergePDFNameFields; + + + @Override + public String execute(RequestInfo requestInfo) { + ToolUtil toolUtil = new ToolUtil(); + toolUtil.writeErrorLog("进入PDF转换action!"); + User user = requestInfo.getRequestManager().getUser(); + String billTableName = requestInfo.getRequestManager().getBillTableName(); + String requestId = requestInfo.getRequestid(); + String workflowId = requestInfo.getWorkflowid(); + if(StringUtils.isNullOrEmpty(mergeField)){ + return Action.SUCCESS; + } + if(StringUtils.isNullOrEmpty(mergeToField)){ +// TODO 修改labelId + requestInfo.getRequestManager().setMessagecontent(Util.getHtmlLabelName(-10101,user.getLanguage(),"没有配置合并后PDF存放字段,请联系管理员!")); + requestInfo.getRequestManager().setMessageid("1"); + return Action.FAILURE_AND_CONTINUE; + } +// 获取流程数据 + RecordSet rs = new RecordSet(); + String query = "select * from " + billTableName + " where requestid = ?"; + rs.executeQuery(query,requestId); + Map workflowData = Util.recordSet2Map(rs); + if(workflowData == null){ + toolUtil.writeErrorLog("未查询到流程数据:" + query + " --> " + requestId); + return Action.SUCCESS; + } +// 获取文件id + String docIds = Util.null2String(workflowData.get(mergeField)); + if(StringUtils.isNullOrEmpty(docIds)){ + return Action.SUCCESS; + } +// 查询字段的目录 + String docCategorys = Util.getDocCategorys(workflowId, mergeField); + CreateDocForJSGJXT createDocForJSGJXT = new CreateDocForJSGJXT(); + String[] docCategoryArray = docCategorys.split(","); + int docCategory = 0; + if(docCategoryArray.length == 3){ + docCategory = Integer.parseInt(docCategoryArray[2]); + }else{ + for (String s : docCategoryArray) { + docCategory = Integer.parseInt(s); + } + } + String fileName = ""; + String defaultFileName = "合同水印合并文件"; + if("1".equals(mergePDFNameType)){ +// 1.流程字段,2,action参数,3流程字段+action参数,4 流程多字段拼接 + String fields = Util.null2String(workflowData.get(mergePDFNameFields)); + String[] fieldArr = fields.split(","); + fileName = Util.null2DefaultStr(workflowData.get(fieldArr[0]),defaultFileName); + }else if("2".equals(mergePDFNameType)){ +// 1.流程字段,2,action参数,3流程字段+action参数,4 流程多字段拼接 + fileName = mergePDFName; + }else if("3".equals(mergePDFNameType)){ +// 1.流程字段,2,action参数,3流程字段+action参数,4 流程多字段拼接 + fileName = Util.null2DefaultStr(workflowData.get(mergePDFNameFields),defaultFileName) + mergePDFName; + }else if("4".equals(mergePDFNameType)){ +// 1.流程字段,2,action参数,3流程字段+action参数,4 流程多字段拼接 + String fields = Util.null2String(workflowData.get(mergePDFNameFields)); + String[] fieldArr = fields.split(","); + for (String field : fieldArr) { + fileName += Util.null2String(workflowData.get(field)); + } + } + if(StringUtils.isNullOrEmpty(fileName)){ + fileName = defaultFileName; + } + int fileId = createDocForJSGJXT.creatDoc(user, fileName, docCategory, docIds); + if(fileId <= 0){ + toolUtil.writeErrorLog("文件合并错误!(-2:用户为空,-1:文档获取异常)、错误id:" + fileId); +// TODO 修改labelId + requestInfo.getRequestManager().setMessagecontent(Util.getHtmlLabelName(-10101,user.getLanguage(),"没有配置合并后PDF存放字段,请联系管理员!")); + requestInfo.getRequestManager().setMessageid("1"); + return Action.FAILURE_AND_CONTINUE; + } +// 将合并的文件回写到流程中 + PrepSqlResultImpl sqlResult = Util.createSqlBuilder().updateSql(billTableName, ParaMap.create().put(mergeToField, fileId), + Util.createPrepWhereImpl().whereAnd("requestid").whereEqual(requestId)); + toolUtil.writeErrorLog("数据回写:" + sqlResult.getSqlStr() + " --> 参数: " + sqlResult.getArgs()); + rs.executeUpdate(sqlResult.getSqlStr(),sqlResult.getArgs()); + return Action.SUCCESS; + } + + public String getMergeField() { + return mergeField; + } + + public void setMergeField(String mergeField) { + this.mergeField = mergeField; + } + + public String getMergeToField() { + return mergeToField; + } + + public void setMergeToField(String mergeToField) { + this.mergeToField = mergeToField; + } + + public String getMergePDFNameType() { + return mergePDFNameType; + } + + public void setMergePDFNameType(String mergePDFNameType) { + this.mergePDFNameType = mergePDFNameType; + } + + public String getMergePDFName() { + return mergePDFName; + } + + public void setMergePDFName(String mergePDFName) { + this.mergePDFName = mergePDFName; + } + + public String getMergePDFNameFields() { + return mergePDFNameFields; + } + + public void setMergePDFNameFields(String mergePDFNameFields) { + this.mergePDFNameFields = mergePDFNameFields; + } +}