diff --git a/v5/apps-customize/src/main/java/com/seeyon/apps/src_saomaoyi/SaoMiaoYiPluginApi.java b/v5/apps-customize/src/main/java/com/seeyon/apps/src_saomaoyi/SaoMiaoYiPluginApi.java new file mode 100644 index 0000000..4f8e8df --- /dev/null +++ b/v5/apps-customize/src/main/java/com/seeyon/apps/src_saomaoyi/SaoMiaoYiPluginApi.java @@ -0,0 +1,43 @@ +package com.seeyon.apps.src_saomaoyi; + +import com.seeyon.apps.common.plugin.api.APluginInfoApi; +import com.seeyon.apps.common.plugin.vo.ConfigVo; +import com.seeyon.apps.src_saomaoyi.constants.SaoMiaoYiConstants; +import org.springframework.stereotype.Component; + +@Component +public class SaoMiaoYiPluginApi extends APluginInfoApi { + + public SaoMiaoYiPluginApi() { + } + + public String getPluginId() { + System.out.println(SaoMiaoYiConstants.getPluginId()); + return SaoMiaoYiConstants.getPluginId(); + } + + public String getCreateUser() { + return "橙阳科技"; + } + + public String getDescription() { + return "三峡旅游水扫描仪控件"; + } + + public ConfigVo getDefaultConfig() { + ConfigVo configVo = new ConfigVo(); + SaoMiaoYiConstants[] var2 = SaoMiaoYiConstants.values(); + int var3 = var2.length; + + for(int var4 = 0; var4 < var3; ++var4) { + SaoMiaoYiConstants value = var2[var4]; + if (value != SaoMiaoYiConstants.plugin) { + configVo.getDevParams().put(value.name(), value.getDefaultValue()); + configVo.getProdParams().put(value.name(), value.getDefaultValue()); + configVo.getParamMap().put(value.name(), value.getDescription()); + } + } + + return configVo; + } +} diff --git a/v5/apps-customize/src/main/java/com/seeyon/apps/src_saomaoyi/btn/SaoMiaoYiImgBtn.java b/v5/apps-customize/src/main/java/com/seeyon/apps/src_saomaoyi/btn/SaoMiaoYiImgBtn.java new file mode 100644 index 0000000..afb96f1 --- /dev/null +++ b/v5/apps-customize/src/main/java/com/seeyon/apps/src_saomaoyi/btn/SaoMiaoYiImgBtn.java @@ -0,0 +1,54 @@ +package com.seeyon.apps.src_saomaoyi.btn; + +import com.seeyon.cap4.form.bean.button.CommonBtn; +import com.seeyon.cap4.form.util.Enums; +import org.springframework.stereotype.Component; + +@Component +public class SaoMiaoYiImgBtn extends CommonBtn { + @Override + public String getPCInjectionInfo() { + return "{\"path\":\"apps_res/cap/customCtrlResources/saomiaoyiBtnResources/\",\"jsUri\":\"js/img.js\",\"initMethod\":\"init\",\"nameSpace\":\"" + + this.getNameSpace() + "\"}"; + } + + @Override + public String getMBInjectionInfo() { + return null; + } + + @Override + public String getKey() { + return "1992789877417263104"; + } + + @Override + public boolean canUse(Enums.FormType formType) { + return true; + } + + public String getNameSpace() { + return "customBtn_" + this.getKey(); + } + + public String getFieldLength() { + return "20"; + } + @Override + public String getText() { + return "获取扫描仪图片按钮"; + } + + /** + * 控件初始化接口,此接口在控件初始化的时候,会调用,主要用于定义控件所属插件id、在表单编辑器中的图标、表单编辑器中有哪些属性可以设置。 + * 使用举例:在接口中定义自定义控件在在表单编辑器中有哪些控件属性需要配置 + */ + @Override + public void init() { + //设置图标和插件ID + setPluginId("src_saomiaoyi"); + setIcon("cap-icon-custom-button"); + // 自定义参数 + } + +} diff --git a/v5/apps-customize/src/main/java/com/seeyon/apps/src_saomaoyi/btn/SaoMiaoYiInitBtn.java b/v5/apps-customize/src/main/java/com/seeyon/apps/src_saomaoyi/btn/SaoMiaoYiInitBtn.java new file mode 100644 index 0000000..d8acdee --- /dev/null +++ b/v5/apps-customize/src/main/java/com/seeyon/apps/src_saomaoyi/btn/SaoMiaoYiInitBtn.java @@ -0,0 +1,54 @@ +package com.seeyon.apps.src_saomaoyi.btn; + +import com.seeyon.cap4.form.bean.button.CommonBtn; +import com.seeyon.cap4.form.util.Enums; +import org.springframework.stereotype.Component; + +@Component +public class SaoMiaoYiInitBtn extends CommonBtn { + @Override + public String getPCInjectionInfo() { + return "{\"path\":\"apps_res/cap/customCtrlResources/saomiaoyiBtnResources/\",\"jsUri\":\"js/init.js\",\"initMethod\":\"init\",\"nameSpace\":\"" + + this.getNameSpace() + "\"}"; + } + + @Override + public String getMBInjectionInfo() { + return null; + } + + @Override + public String getKey() { + return "1992789877417263105"; + } + + @Override + public boolean canUse(Enums.FormType formType) { + return true; + } + + public String getNameSpace() { + return "customBtn_" + this.getKey(); + } + + public String getFieldLength() { + return "20"; + } + @Override + public String getText() { + return "初始化扫描仪按钮"; + } + + /** + * 控件初始化接口,此接口在控件初始化的时候,会调用,主要用于定义控件所属插件id、在表单编辑器中的图标、表单编辑器中有哪些属性可以设置。 + * 使用举例:在接口中定义自定义控件在在表单编辑器中有哪些控件属性需要配置 + */ + @Override + public void init() { + //设置图标和插件ID + setPluginId("src_saomiaoyi"); + setIcon("cap-icon-custom-button"); + // 自定义参数 + } + +} diff --git a/v5/apps-customize/src/main/java/com/seeyon/apps/src_saomaoyi/config/SaoMiaoYiPluginConfigProvider.java b/v5/apps-customize/src/main/java/com/seeyon/apps/src_saomaoyi/config/SaoMiaoYiPluginConfigProvider.java new file mode 100644 index 0000000..ba40e1e --- /dev/null +++ b/v5/apps-customize/src/main/java/com/seeyon/apps/src_saomaoyi/config/SaoMiaoYiPluginConfigProvider.java @@ -0,0 +1,17 @@ +package com.seeyon.apps.src_saomaoyi.config; + +import com.seeyon.apps.common.config.ICstConfigApi; +import com.seeyon.apps.common.plugin.vo.ConfigVo; +import com.seeyon.apps.src_saomaoyi.constants.SaoMiaoYiConstants; +import com.seeyon.ctp.common.AppContext; + +import static com.seeyon.apps.src_saomaoyi.constants.SaoMiaoYiConstants.getPluginId; + +public class SaoMiaoYiPluginConfigProvider { + protected ICstConfigApi cstConfigApi = (ICstConfigApi) AppContext.getBean("cstConfigApi"); + + public String getBizConfigByKey(SaoMiaoYiConstants key) { + ConfigVo config = cstConfigApi.getConfig(getPluginId()); + return config.getParamVal(key.name()); + } +} diff --git a/v5/apps-customize/src/main/java/com/seeyon/apps/src_saomaoyi/constants/SaoMiaoYiConstants.java b/v5/apps-customize/src/main/java/com/seeyon/apps/src_saomaoyi/constants/SaoMiaoYiConstants.java new file mode 100644 index 0000000..0d993e6 --- /dev/null +++ b/v5/apps-customize/src/main/java/com/seeyon/apps/src_saomaoyi/constants/SaoMiaoYiConstants.java @@ -0,0 +1,30 @@ +package com.seeyon.apps.src_saomaoyi.constants; + +public enum SaoMiaoYiConstants { + + plugin("src_saomiaoyi","插件ID"), + formDataLoginName("wukangqiao","档案表创建人"), + updateAccountName("wukangqiao","更新账号"), + updateLoginName("wukangqiao","更新登录名"), + formCode("smy","表单编码"), + ; + + private String defaultValue; + private String description; + + SaoMiaoYiConstants(String defaultValue,String description) { + this.defaultValue = defaultValue; + this.description = description; + } + + public String getDescription() { + return description; + } + + public String getDefaultValue() { + return defaultValue; + } + public static String getPluginId() { + return plugin.defaultValue; + } +} diff --git a/v5/apps-customize/src/main/java/com/seeyon/apps/src_saomaoyi/invoice/InvoiceImgSaveService.java b/v5/apps-customize/src/main/java/com/seeyon/apps/src_saomaoyi/invoice/InvoiceImgSaveService.java new file mode 100644 index 0000000..8a38e5a --- /dev/null +++ b/v5/apps-customize/src/main/java/com/seeyon/apps/src_saomaoyi/invoice/InvoiceImgSaveService.java @@ -0,0 +1,8 @@ +package com.seeyon.apps.src_saomaoyi.invoice; + +import java.io.InputStream; + +public interface InvoiceImgSaveService { + + void saveInvoiceImg(InputStream is) throws Exception; +} diff --git a/v5/apps-customize/src/main/java/com/seeyon/apps/src_saomaoyi/invoice/InvoiceImgSaveServiceImpl.java b/v5/apps-customize/src/main/java/com/seeyon/apps/src_saomaoyi/invoice/InvoiceImgSaveServiceImpl.java new file mode 100644 index 0000000..d51e727 --- /dev/null +++ b/v5/apps-customize/src/main/java/com/seeyon/apps/src_saomaoyi/invoice/InvoiceImgSaveServiceImpl.java @@ -0,0 +1,143 @@ +package com.seeyon.apps.src_saomaoyi.invoice; + +import com.seeyon.apps.src_saomaoyi.config.SaoMiaoYiPluginConfigProvider; +import com.seeyon.apps.src_saomaoyi.constants.SaoMiaoYiConstants; +import com.seeyon.apps.src_saomaoyi.utils.*; +import com.seeyon.ctp.common.AppContext; +import com.seeyon.ctp.common.filemanager.manager.AttachmentManager; +import com.seeyon.ctp.common.po.filemanager.Attachment; +import com.seeyon.ctp.organization.bo.V3xOrgAccount; +import com.seeyon.ctp.organization.bo.V3xOrgMember; +import com.seeyon.ctp.organization.manager.OrgManager; +import com.seeyon.ctp.services.FileUploadExporter; +import com.seeyon.v3x.services.form.FormFactory; +import com.seeyon.v3x.services.form.bean.FormExport; +import com.seeyon.v3x.services.form.bean.ValueExport; + +import java.io.*; +import java.text.SimpleDateFormat; +import java.util.*; + +public class InvoiceImgSaveServiceImpl implements InvoiceImgSaveService { + + private FormFactory formFactory; + + private SaoMiaoYiPluginConfigProvider configProvider = (SaoMiaoYiPluginConfigProvider) AppContext.getBean("saoMiaoYiPluginConfigProvider"); + + public FormFactory getFormFactory() { + if (formFactory == null) { + formFactory = (FormFactory) AppContext.getBean("formFactory"); + } + return formFactory; + } + public void setFormFactory(FormFactory formFactory) { + this.formFactory = formFactory; + } + + @Override + public void saveInvoiceImg(InputStream is) throws Exception { + String code = insertRecord(); + String formCode = configProvider.getBizConfigByKey(SaoMiaoYiConstants.formCode); + FormDataOperator formDataOperator = new FormDataOperator(); + List condiitonVo = new ArrayList<>(); + List updateFields = new ArrayList<>(); + condiitonVo.add(FormWhereCondition.build().display("编号").value(code)); + + List formColumns = formDataOperator.queryFormDataCondition(formCode, null, condiitonVo); + if (formColumns == null || formColumns.size() == 0) { + throw new RuntimeException("查询错误"); + } + String formId = formColumns.get(0).getId(); + String refId = bindFileRef(formId,is); + updateFields.add(FormUpdateField.build().value(refId).display("文件")); + List whereClause = new ArrayList<>(); + whereClause.add(FormWhereCondition.build().display("ID").value(Long.parseLong(formId))); + formDataOperator.updateMasterForm(formCode, updateFields, whereClause); + } + + private String bindFileRef(String formId, InputStream is) throws Exception { + String refId = Math.abs(UUID.randomUUID().getLeastSignificantBits()) + ""; + String localFilePath = System.getProperty("java.io.tmpdir") + File.separator + "seeyontempfile"; + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + + String tempFileName = UUID.randomUUID() + ".pdf"; + File tempFileParent = new File(localFilePath); + + if (!tempFileParent.exists()) { + tempFileParent.mkdirs(); + } + + File tempFile = new File(tempFileParent, tempFileName); + + // ----------- 关键修复:用字节流复制 InputStream 到 PDF ----------- + try (InputStream input = is; + OutputStream output = new FileOutputStream(tempFile)) { + + byte[] buffer = new byte[8192]; + int len; + while ((len = input.read(buffer)) != -1) { + output.write(buffer, 0, len); + } + } catch (Exception e) { + throw new RuntimeException("保存临时 PDF 文件失败", e); + } + + // 限制 100MB + if (tempFile.length() > 102400000) { + tempFile.delete(); + return null; + } + + // 调用 Seeyon 附件服务上传 + FileUploadExporter fileUpload = new FileUploadExporter(); + String uploadResult = fileUpload.processUpload(new String[]{tempFile.getAbsolutePath()}); + + Map map = new HashMap<>(); + map.put("type", "0"); + map.put("fileUrl", uploadResult); + map.put("mimeType", "application/pdf"); + map.put("size", String.valueOf(tempFile.length())); + map.put("subReference", refId); + map.put("category", "66"); + map.put("createdate", sdf.format(new Date())); + map.put("filename", tempFileName); + map.put("reference", formId); + + // 删除本地临时文件 + tempFile.delete(); + + Attachment attachment = new Attachment(map); + OrgManager orgManager = (OrgManager) AppContext.getBean("orgManager"); + AttachmentManager attachmentManager = (AttachmentManager) AppContext.getBean("attachmentManager"); + + String loginName = configProvider.getBizConfigByKey(SaoMiaoYiConstants.formDataLoginName); + String updateAccountName = configProvider.getBizConfigByKey(SaoMiaoYiConstants.updateAccountName); + + V3xOrgMember member = orgManager.getMemberByLoginName(loginName); + V3xOrgAccount account = orgManager.getAccountByName(updateAccountName); + + attachmentManager.create(Collections.singletonList(attachment), member.getId(), account.getId()); + + return refId; + } + + + public String insertRecord() throws Exception { + String code = UUID.randomUUID().toString().replace("-", ""); + String loginName = configProvider.getBizConfigByKey(SaoMiaoYiConstants.formDataLoginName); + String formCode = configProvider.getBizConfigByKey(SaoMiaoYiConstants.formCode); + Map map = new HashMap(); + Long currentUserId = AppContext.currentUserId(); + if(currentUserId != null) { + map.put("操作人",currentUserId); + } + map.put("编号", code); + FormExport formExport = new FormExport(); + FormExportUtil formExportUtil = new FormExportUtil(); + List valueExport = formExportUtil.setFormValue(map); + formExport.setValues(valueExport); + getFormFactory().importBusinessFormData(loginName, formCode, + formExport, new String[] {}); + return code; + } +} diff --git a/v5/apps-customize/src/main/java/com/seeyon/apps/src_saomaoyi/utils/ClauseFactor.java b/v5/apps-customize/src/main/java/com/seeyon/apps/src_saomaoyi/utils/ClauseFactor.java new file mode 100644 index 0000000..da43d90 --- /dev/null +++ b/v5/apps-customize/src/main/java/com/seeyon/apps/src_saomaoyi/utils/ClauseFactor.java @@ -0,0 +1,19 @@ +package com.seeyon.apps.src_saomaoyi.utils; + +public enum ClauseFactor { + EQ, //相等 + GT, //大于 + GE, //大于等于 + LT, //小于 + LE, //小于等于 + NULL, //空 + NOT_NULL, //非空 + LIKE, //模糊 + AND, + OR + ; + + public boolean isNullType() { + return this == NULL || this == NOT_NULL; + } +} diff --git a/v5/apps-customize/src/main/java/com/seeyon/apps/src_saomaoyi/utils/EnumMapUtils.java b/v5/apps-customize/src/main/java/com/seeyon/apps/src_saomaoyi/utils/EnumMapUtils.java new file mode 100644 index 0000000..97a6c03 --- /dev/null +++ b/v5/apps-customize/src/main/java/com/seeyon/apps/src_saomaoyi/utils/EnumMapUtils.java @@ -0,0 +1,86 @@ +package com.seeyon.apps.src_saomaoyi.utils; + +import com.seeyon.ctp.common.AppContext; +import com.seeyon.ctp.common.ctpenumnew.manager.EnumManager; +import com.seeyon.ctp.common.po.ctpenumnew.CtpEnumBean; +import com.seeyon.ctp.common.po.ctpenumnew.CtpEnumItem; +import com.seeyon.ctp.util.JDBCAgent; + +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +public class EnumMapUtils { + public static String getEnumItemValue(String rootPCode, String groupValue, String targetValue) { + if(targetValue == null || "null".equals(targetValue) || "".equals(targetValue)){ + return ""; + } + String queryIdSql = "SELECT ce.ID FROM ctp_enum ce inner join ctp_enum cei on ce.`PARENT_ID` = cei.ID where CEI.`PROGRAM_CODE` = ? and ce.`ENUMNAME` = ?"; + Long enumId = null; + JDBCAgent agent = new JDBCAgent(); + try { + agent.execute(queryIdSql, Arrays.asList(rootPCode,groupValue)); + List> list = (List>) agent.resultSetToList(); + if(list == null || list.size() == 0) { + return ""; + } + Map map = list.get(0); + enumId = (Long)map.get("ID"); + } catch (Exception e) { + return ""; + }finally { + agent.close(); + } + EnumManager enumManagerNew = (EnumManager) AppContext.getBean("enumManagerNew"); + CtpEnumBean ctpEnumBean = enumManagerNew.getEnum(enumId); + if(ctpEnumBean == null) { + return ""; + } + List ctpEnumItems = ctpEnumBean.getItems(); + if(ctpEnumBean.getItems() == null) { + return ""; + } + for (CtpEnumItem enumItem : ctpEnumItems) { + if(enumItem.getShowvalue().equals(targetValue)) { + return enumItem.getId() + ""; + } + } + return ""; + } + + public static String getEnumItemValueByEnumId(String showValue,long enumId) { + EnumManager enumManagerNew = (EnumManager) AppContext.getBean("enumManagerNew"); + CtpEnumBean ctpEnumBean = enumManagerNew.getEnum(enumId); + if(ctpEnumBean == null) { + return ""; + } + List ctpEnumItems = ctpEnumBean.getItems(); + if(ctpEnumBean.getItems() == null) { + return ""; + } + for (CtpEnumItem enumItem : ctpEnumItems) { + if(enumItem.getShowvalue().equals(showValue)) { + return enumItem.getId() + ""; + } + } + return ""; + } + + public static String getEnumItemValueByEnumIdAndEnumValue(String value,long enumId) { + EnumManager enumManagerNew = (EnumManager) AppContext.getBean("enumManagerNew"); + CtpEnumBean ctpEnumBean = enumManagerNew.getEnum(enumId); + if(ctpEnumBean == null) { + return ""; + } + List ctpEnumItems = ctpEnumBean.getItems(); + if(ctpEnumBean.getItems() == null) { + return ""; + } + for (CtpEnumItem enumItem : ctpEnumItems) { + if(enumItem.getValue().equals(value)) { + return enumItem.getId() + ""; + } + } + return ""; + } +} diff --git a/v5/apps-customize/src/main/java/com/seeyon/apps/src_saomaoyi/utils/FormColumn.java b/v5/apps-customize/src/main/java/com/seeyon/apps/src_saomaoyi/utils/FormColumn.java new file mode 100644 index 0000000..850967d --- /dev/null +++ b/v5/apps-customize/src/main/java/com/seeyon/apps/src_saomaoyi/utils/FormColumn.java @@ -0,0 +1,24 @@ +package com.seeyon.apps.src_saomaoyi.utils; + +import java.util.List; + +public class FormColumn { + private String id; + private List vos; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public List getVos() { + return vos; + } + + public void setVos(List vos) { + this.vos = vos; + } +} diff --git a/v5/apps-customize/src/main/java/com/seeyon/apps/src_saomaoyi/utils/FormDataOperator.java b/v5/apps-customize/src/main/java/com/seeyon/apps/src_saomaoyi/utils/FormDataOperator.java new file mode 100644 index 0000000..309d9a4 --- /dev/null +++ b/v5/apps-customize/src/main/java/com/seeyon/apps/src_saomaoyi/utils/FormDataOperator.java @@ -0,0 +1,630 @@ +package com.seeyon.apps.src_saomaoyi.utils; + +import com.alibaba.fastjson.JSONObject; +import com.seeyon.aicloud.common.JsonUtils; +import com.seeyon.apps.src_powerfeeinvoice.config.HttpFormRestApiConfig; +import com.seeyon.cap4.form.api.FormApi4Cap4; +import com.seeyon.cap4.form.bean.FormBean; +import com.seeyon.cap4.form.bean.FormFieldBean; +import com.seeyon.cap4.form.bean.FormTableBean; +import com.seeyon.ctp.common.AppContext; +import com.seeyon.ctp.common.exceptions.BusinessException; +import com.seeyon.ctp.util.JDBCAgent; +import org.apache.commons.httpclient.HttpStatus; +import org.apache.http.HttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.impl.client.DefaultHttpClient; +import org.apache.http.message.BasicHeader; +import org.apache.http.util.EntityUtils; +import www.seeyon.com.utils.StringUtil; + +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.*; +import java.util.stream.Collectors; + +public class FormDataOperator { + + public void updateMasterForm(String formNo, List updateFieldVos, List conditionVos) throws BusinessException { + FormApi4Cap4 formApi4Cap4 = (FormApi4Cap4) AppContext.getBean("formApi4Cap4"); + FormBean cap4FormBean = formApi4Cap4.getFormByFormCode(formNo); + FormTableBean masterTableBean = cap4FormBean.getMasterTableBean(); + if (updateFieldVos == null) { + throw new IllegalArgumentException("要修改的字段为空"); + } + for (FormUpdateField fieldVo : updateFieldVos) { + FormFieldBean bean = masterTableBean.getFieldBeanByDisplay(fieldVo.getDisplay()); + if (bean == null) { + continue; + } + if(bean.getInputType().equals("image") || bean.getInputType().equals("attachment")) { + + } + fieldVo.fieldName(bean.getColumnName()); + } + List updateFields = updateFieldVos.stream().filter(u -> u.getFieldName() != null).collect(Collectors.toList()); + for (FormWhereCondition conditionVo : conditionVos) { + FormFieldBean bean = masterTableBean.getFieldBeanByDisplay(conditionVo.getDisplay()); + if (bean == null) { + if (conditionVo.getDisplay().equals("ID") || conditionVo.getDisplay().equals("id")) { + conditionVo.setFieldName(conditionVo.getDisplay()); + } + continue; + } + conditionVo.setFieldName(bean.getColumnName()); + } + List conditions = conditionVos.stream().filter(c -> c.getFieldName() != null).collect(Collectors.toList()); + Map map = generateSql(updateFields, masterTableBean.getTableName(), conditions); + JDBCAgent agent = new JDBCAgent(); + try { + agent.execute((String) map.get("sql"), (List) map.get("params")); + return; + } catch (Exception e) { + e.printStackTrace(); + } finally { + agent.close(); + } + } + + public Long countCondition(String formNo,List conditionVos) throws BusinessException { + FormApi4Cap4 formApi4Cap4 = (FormApi4Cap4) AppContext.getBean("formApi4Cap4"); + FormBean cap4FormBean = formApi4Cap4.getFormByFormCode(formNo); + FormTableBean masterTableBean = cap4FormBean.getMasterTableBean(); + String tableName = masterTableBean.getTableName(); + for (FormWhereCondition conditionVo : conditionVos) { + FormFieldBean fieldBeanByDisplay = masterTableBean.getFieldBeanByDisplay(conditionVo.getDisplay()); + if (fieldBeanByDisplay == null) { + continue; + } + conditionVo.setFieldName(fieldBeanByDisplay.getColumnName()); + } + + Map generateSql = generateSql(conditionVos, tableName); + String sql = (String) generateSql.get("sql"); + List params = (List) generateSql.get("params"); + JDBCAgent jdbcAgent = new JDBCAgent(); + try { + jdbcAgent.execute(sql, params); + return (Long) jdbcAgent.resultSetToMap().get("countsize"); + } catch (Exception e) { + System.out.println(e.getMessage()); + } finally { + jdbcAgent.close(); + } + return null; + } + + public void refreshForm(String id, String formNo, String formLoginName, HttpFormRestApiConfig config) throws BusinessException, IOException { + FormApi4Cap4 formApi4Cap4 = (FormApi4Cap4) AppContext.getBean("formApi4Cap4"); + FormBean cap4FormBean = formApi4Cap4.getFormByFormCode(formNo); + FormTableBean masterTableBean = cap4FormBean.getMasterTableBean(); + List dataList = new ArrayList<>(); + Map temp1 = new HashMap<>(); + Map temp2 = new HashMap<>(); + temp1.put("masterTable",temp2); + temp2.put("name",masterTableBean.getTableName()); + Map recordMap = new HashMap<>(3); // 容量=3 (2/0.75≈2.67) + recordMap.put("id", id); + recordMap.put("fields", new ArrayList<>()); + temp2.put("record", recordMap); + temp2.put("changedFields",new ArrayList<>()); + dataList.add(temp1); + String token = getToken(config.getTokenUrl(),config.getRestUserName(),config.getRestPwd(),formLoginName); + Map beanMap = new HashMap(); + beanMap.put("formCode", formNo); + beanMap.put("loginName", formLoginName); + beanMap.put("doTrigger", "true"); + beanMap.put("rightId", config.getRightId()); + beanMap.put("dataList",dataList); + Map header = new HashMap<>(); + header.put("token", token); + String url = config.getBaseUrl() + "/seeyon/rest/cap4/form/soap/batch-update"; + String response = HttpClient.httpPostRaw(url, JsonUtils.toJSONString(beanMap), header, "UTF-8"); + System.out.println(response); + } + private String getToken(String oatokenurl,String restName,String restPassword,String loginName) throws FileNotFoundException, IOException { + String address = oatokenurl + restName + "/" + restPassword; + if(StringUtil.isNotEmpty(loginName)){ + address = address +"?loginName="+loginName; + } + DefaultHttpClient client = new DefaultHttpClient(); + String result = ""; + HttpGet get = new HttpGet(address); + // 添加 Headers 信息 + get.addHeader(new BasicHeader("Accept", "application/json")); + try { + HttpResponse res = client.execute(get); + if (res.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { + result = EntityUtils.toString(res.getEntity()); + } + } catch (Exception e) { + throw new RuntimeException(e); + } + String token = ""; + if(result.contains("{")) { + JSONObject jsObj = JSONObject.parseObject(result); + token = jsObj.get("id").toString(); + }else { + token = result; + } + return token; + } + + public List queryFormDataCondition(String formNo, List queryColumnVos, List conditionVos) throws BusinessException { + FormApi4Cap4 formApi4Cap4 = (FormApi4Cap4) AppContext.getBean("formApi4Cap4"); + FormBean cap4FormBean = formApi4Cap4.getFormByFormCode(formNo); + List queryColumns = new ArrayList<>(); + FormTableBean masterTableBean = cap4FormBean.getMasterTableBean(); + String tableName = masterTableBean.getTableName(); + Map fieldMap4Name = masterTableBean.getFieldMap4Name(); + if (queryColumnVos != null) { + for (String queryColumnVo : queryColumnVos) { + FormFieldBean fieldBeanByDisplay = masterTableBean.getFieldBeanByDisplay(queryColumnVo); + if (fieldBeanByDisplay == null) { + continue; + } + queryColumns.add(fieldBeanByDisplay.getColumnName()); + } + } + for (FormWhereCondition conditionVo : conditionVos) { + FormFieldBean fieldBeanByDisplay = masterTableBean.getFieldBeanByDisplay(conditionVo.getDisplay()); + if (fieldBeanByDisplay == null) { + if (conditionVo.getDisplay().equals("ID") || conditionVo.getDisplay().equals("id")) { + conditionVo.setFieldName(conditionVo.getDisplay()); + } + continue; + } + conditionVo.setFieldName(fieldBeanByDisplay.getColumnName()); + } + + Map generateSql = generateSql(queryColumns, conditionVos, tableName); + String sql = (String) generateSql.get("sql"); + List params = (List) generateSql.get("params"); + JDBCAgent jdbcAgent = new JDBCAgent(); + List columns = new ArrayList<>(); + try { + jdbcAgent.execute(sql, params); + List list = jdbcAgent.resultSetToList(); + for (Object o : list) { + FormColumn column = new FormColumn(); + Map columnMap = (Map) o; + List vos = new ArrayList<>(); + for (String key : columnMap.keySet()) { + FormFieldVo fieldVo = new FormFieldVo(); + if (fieldMap4Name.containsKey(key)) { + FormFieldBean fieldBean = fieldMap4Name.get(key); + fieldVo.setDisplayName(fieldBean.getDisplay()); + fieldVo.setValue(columnMap.get(key)); + vos.add(fieldVo); + } + } + column.setVos(vos); + if (columnMap.get("id") != null) { + column.setId(columnMap.get("id") + ""); + } + columns.add(column); + } + return columns; + } catch (Exception e) { + System.out.println(e.getMessage()); + } finally { + jdbcAgent.close(); + } + return null; + } + + private Map generateSql(List conditions, String tableName) { + if (tableName == null) { + throw new IllegalArgumentException("tableName cannot be null or empty"); + } + StringBuilder sqlBuilder = new StringBuilder("SELECT count(*) as countSize "); + sqlBuilder.append(" from " + tableName); + List params = new ArrayList<>(); + sqlBuilder.append(buildWhereClause(conditions,params)); + Map result = new HashMap<>(); + result.put("sql", sqlBuilder.toString()); + result.put("params", params); + return result; + } + + private Map generateSql(List queryColumn, List conditions, String tableName) { + if (tableName == null) { + throw new IllegalArgumentException("tableName cannot be null or empty"); + } + StringBuilder sqlBuilder = new StringBuilder("SELECT "); + if (queryColumn == null || queryColumn.isEmpty()) { + sqlBuilder.append("*"); + } + + for (int i = 0; i < queryColumn.size(); i++) { + sqlBuilder.append(queryColumn.get(i)); + if (queryColumn.size() > 1 && i >= 0 && i < queryColumn.size() - 1) { + sqlBuilder.append(","); + } + } + + if (queryColumn.size() > 0) { + sqlBuilder.append(",`ID`"); + } + + sqlBuilder.append(" from " + tableName); + List params = new ArrayList<>(); + sqlBuilder.append(buildWhereClause(conditions,params)); + Map result = new HashMap<>(); + result.put("sql", sqlBuilder.toString()); + result.put("params", params); + return result; + } + + private Map generateSql(List fieldValues, String tableName, List conditions) { + if (fieldValues == null || fieldValues.isEmpty()) { + throw new IllegalArgumentException("Field values cannot be null or empty"); + } + if (tableName == null || tableName.trim().isEmpty()) { + throw new IllegalArgumentException("Table name cannot be null or empty"); + } + StringBuilder sqlBuilder = new StringBuilder("UPDATE ").append(tableName).append(" SET "); + List params = new ArrayList<>(); + // Build the SET clause + int fieldCount = 0; + for (FormUpdateField updateField : fieldValues) { + if (updateField.getValue() == null || "".equals(updateField.getValue()) || "null".equals(updateField.getValue())) { + continue; + } + if (fieldCount > 0) { + sqlBuilder.append(", "); + } + if (updateField.getValue() instanceof String && ((String) updateField.getValue()).startsWith("DATE>")) { + String oldValue = (String) updateField.getValue(); + sqlBuilder.append(updateField.getFieldName()).append(" = TO_DATE( ?, 'YYYY-MM-DD')"); + updateField.setValue(oldValue.substring(oldValue.indexOf(">") + 1)); + } else { + sqlBuilder.append(updateField.getFieldName()).append(" = ?"); + } + params.add(updateField.getValue()); + fieldCount++; + } + String whereClauseStr = buildWhereClause(conditions,params); + // Append the WHERE clause + sqlBuilder.append(whereClauseStr); + // Create result map + Map result = new HashMap<>(); + result.put("sql", sqlBuilder.toString()); + result.put("params", params); + return result; + } + + public Map> getMainFormTableAttachments(String formNo,Map sourceMap) throws BusinessException { + FormApi4Cap4 formApi4Cap4 = (FormApi4Cap4) AppContext.getBean("formApi4Cap4"); + FormBean cap4FormBean = formApi4Cap4.getFormByFormCode(formNo); + FormTableBean masterTableBean = cap4FormBean.getMasterTableBean(); + Map> attachmentTempMap = new HashMap<>(); + Set removeKey = new HashSet<>(); + for (String key : sourceMap.keySet()) { + FormFieldBean fieldBeanByDisplay = masterTableBean.getFieldBeanByDisplay(key); + if(fieldBeanByDisplay == null ){ + continue; + } + if(fieldBeanByDisplay.getInputType().equals("image") || + fieldBeanByDisplay.getInputType().equals("attachment")) { + attachmentTempMap.put(fieldBeanByDisplay.getDisplay(),(List)sourceMap.get(key)); + removeKey.add(key); + } + } + for (String key : removeKey) { + sourceMap.remove(key); + } + return attachmentTempMap; + } + + public Map> getSubFormTableAttachments(String formNo,Map sourceMap) throws BusinessException { + FormApi4Cap4 formApi4Cap4 = (FormApi4Cap4) AppContext.getBean("formApi4Cap4"); + FormBean cap4FormBean = formApi4Cap4.getFormByFormCode(formNo); + List subTableBean = cap4FormBean.getSubTableBean(); + Map> attachmentTempMap = new HashMap<>(); + String tableName = null; + for (String key : sourceMap.keySet()) { + tableName = key; + } + String finalTableName = tableName; + FormTableBean tableBean = subTableBean.stream().filter(s->s.getTableName().equals(finalTableName)).collect(Collectors.toList()).get(0); + List> tableData = (List>)sourceMap.get(tableName); + Set removeKey = new HashSet<>(); + for (Map rowData : tableData) { + for (String key : rowData.keySet()) { + FormFieldBean fieldBeanByDisplay = tableBean.getFieldBeanByDisplay(key); + if(fieldBeanByDisplay == null ){ + continue; + } + if(fieldBeanByDisplay.getInputType().equals("image") || + fieldBeanByDisplay.getInputType().equals("attachment")) { + attachmentTempMap.put(fieldBeanByDisplay.getDisplay(),(List)sourceMap.get(key)); + removeKey.add(key); + } + } + for (String key : removeKey) { + rowData.remove(key); + } + removeKey.clear(); + } + return attachmentTempMap; + } + + public void addSubTableRecord(String subTableName,List data,String formNo,String formId) { + JDBCAgent agent = new JDBCAgent(); + try { + FormApi4Cap4 formApi4Cap4 = (FormApi4Cap4) AppContext.getBean("formApi4Cap4"); + FormBean cap4FormBean = formApi4Cap4.getFormByFormCode(formNo); + List tableBean = cap4FormBean.getSubTableBean(); + for (FormTableBean bean : tableBean) { + if(!bean.getTableName().equals(subTableName)) { + continue; + } + for (Object column : data) { + Map map = (Map) column; + Map tempMap = new HashMap<>(); + for (String key : map.keySet()) { + FormFieldBean fieldBeanByDisplay = bean.getFieldBeanByDisplay(key); + if(fieldBeanByDisplay == null) { + continue; + } + tempMap.put(fieldBeanByDisplay.getColumnName(),map.get(key)); + } + tempMap.put("formmain_id",formId); + tempMap.put("sort",1); + tempMap.put("ID",Math.abs(UUID.randomUUID().getLeastSignificantBits())); + Map insertSql = generateInsertSql(tempMap, subTableName); + agent.execute((String)insertSql.get("sql"),(List)insertSql.get("params")); + } + } + } catch (Exception e) { + + } finally { + agent.close(); + } + } + + public void rebuildSubTableRecord(String subTableName,List data,String formNo,String formId) { + String deleteSql = "delete from " + subTableName + " where formmain_id = ? "; + JDBCAgent agent = new JDBCAgent(); + try { + agent.execute(deleteSql, Arrays.asList(formId)); + FormApi4Cap4 formApi4Cap4 = (FormApi4Cap4) AppContext.getBean("formApi4Cap4"); + FormBean cap4FormBean = formApi4Cap4.getFormByFormCode(formNo); + List tableBean = cap4FormBean.getSubTableBean(); + for (FormTableBean bean : tableBean) { + if(!bean.getTableName().equals(subTableName)) { + continue; + } + for (Object column : data) { + Map map = (Map) column; + Map tempMap = new HashMap<>(); + for (String key : map.keySet()) { + FormFieldBean fieldBeanByDisplay = bean.getFieldBeanByDisplay(key); + if(fieldBeanByDisplay == null) { + continue; + } + tempMap.put(fieldBeanByDisplay.getColumnName(),map.get(key)); + } + tempMap.put("formmain_id",formId); + tempMap.put("sort",1); + tempMap.put("ID",Math.abs(UUID.randomUUID().getLeastSignificantBits())); + Map insertSql = generateInsertSql(tempMap, subTableName); + agent.execute((String)insertSql.get("sql"),(List)insertSql.get("params")); + } + } + } catch (Exception e) { + + } finally { + agent.close(); + } + } + + public void handleEnumDeptEtc(Map map,String formNo) throws BusinessException { + FormApi4Cap4 formApi4Cap4 = (FormApi4Cap4) AppContext.getBean("formApi4Cap4"); + FormBean cap4FormBean = formApi4Cap4.getFormByFormCode(formNo); + FormTableBean masterTableBean = cap4FormBean.getMasterTableBean(); + for (String key : map.keySet()) { + FormFieldBean fieldBean = masterTableBean.getFieldBeanByDisplay(key); + if(fieldBean == null) { + continue; + } + switch (fieldBean.getInputType()) { + case "select": if(fieldBean.getEnumId() != 0l) { + String enumItemId = EnumMapUtils.getEnumItemValueByEnumId((String)map.get(key),fieldBean.getEnumId()); + map.put(key,enumItemId); + } break; + case "image":break; + case "attachment": break; + case "account": break; + case "department": break; + case "radio": break; + case "member":break; + case "checkbox": + case "date": + case "text":break; + default: break; + + } + } + } + + public void handleSubTableEnumDeptEtc(Map map,String formNo) throws BusinessException { + FormApi4Cap4 formApi4Cap4 = (FormApi4Cap4) AppContext.getBean("formApi4Cap4"); + FormBean cap4FormBean = formApi4Cap4.getFormByFormCode(formNo); + List subTableBean = cap4FormBean.getSubTableBean(); + for (FormTableBean tableBean : subTableBean) { + String tableName = null; + for (String key : map.keySet()) { + tableName = key; + } + if(!tableBean.getTableName().equals(tableName)) { + continue; + } + List> subDatas = (List>) map.get(tableName); + for (Map subData : subDatas) { + for (String key : subData.keySet()) { + FormFieldBean fieldBean = tableBean.getFieldBeanByDisplay(key); + if(fieldBean == null) { + continue; + } + switch (fieldBean.getInputType()) { + case "select": if(fieldBean.getEnumId() != 0l) { + String enumItemId = EnumMapUtils.getEnumItemValueByEnumId((String)subData.get(key),fieldBean.getEnumId()); + subData.put(key,enumItemId); + } break; + case "image":break; + case "attachment": break; + case "account": break; + case "department": break; + case "radio": break; + case "member":break; + case "checkbox": + case "date": + case "text":break; + default: break; + + } + } + } + } + } + + public boolean isMasterTableFile(String displayName,String formNo) { + FormApi4Cap4 formApi4Cap4 = (FormApi4Cap4) AppContext.getBean("formApi4Cap4"); + try { + FormBean cap4FormBean = formApi4Cap4.getFormByFormCode(formNo); + FormTableBean masterTableBean = cap4FormBean.getMasterTableBean(); + FormFieldBean fieldBeanByDisplay = masterTableBean.getFieldBeanByDisplay(displayName); + return fieldBeanByDisplay.getInputType().equals("image") || fieldBeanByDisplay.getInputType().equals("attachment"); + } catch (BusinessException e) { + + } + return false; + } + + private Map generateInsertSql(Map data, String tableName) { + if (tableName == null || tableName.isEmpty()) { + throw new IllegalArgumentException("tableName cannot be null or empty"); + } + if (data == null || data.isEmpty()) { + throw new IllegalArgumentException("data cannot be null or empty"); + } + StringBuilder sqlBuilder = new StringBuilder("INSERT INTO " + tableName + " ("); + List params = new ArrayList<>(); + // 拼接字段名 + StringBuilder columns = new StringBuilder(); + // 拼接字段值 + StringBuilder values = new StringBuilder(); + for (Map.Entry entry : data.entrySet()) { + // 拼接字段名 + if (columns.length() > 0) { + columns.append(", "); + } + columns.append(entry.getKey()); + // 拼接值,使用占位符 ? + if (values.length() > 0) { + values.append(", "); + } + values.append("?"); + // 将值加入 params 列表 + params.add(entry.getValue()); + } + // 完善 SQL 语句 + sqlBuilder.append(columns).append(") VALUES (").append(values).append(");"); + Map result = new HashMap<>(); + result.put("sql", sqlBuilder.toString()); + result.put("params", params); + return result; + } + + /** + * 动态生成 WHERE 子句 + * @param conditions 条件集合 + * @param params 参数列表(引用传递) + * @return 拼接后的 WHERE 子句(包含 WHERE 关键字) + */ + private String buildWhereClause(List conditions, List params) { + if (conditions == null || conditions.isEmpty()) { + return ""; + } + + StringBuilder whereClause = new StringBuilder(" WHERE "); + int conditionIndex = 0; + + for (FormWhereCondition condition : conditions) { + // 处理括号起始 + if (condition.isStartWithBracket()) { + whereClause.append("("); + } + + // 字段名校验 + String fieldName = condition.getFieldName(); + ClauseFactor factor = condition.getClauseFactor(); + String operator = parseOperator(factor); + + // 构建条件表达式 + String conditionExpr; + if (factor != null && factor.isNullType()) { + // 处理 NULL/NOT NULL 条件(无需参数) + conditionExpr = String.format("%s %s", fieldName, operator); + } else { + // 处理普通条件(带占位符) + conditionExpr = String.format("%s %s ?", fieldName, operator); + // 处理函数模板(如 TO_DATE) + if (condition.getIndex() != null) { + conditionExpr = conditionExpr.replace("?", condition.getIndex()); + } + // 添加参数值 + params.add(condition.getValue()); + } + + whereClause.append(conditionExpr); + + // 处理括号闭合 + if (condition.isEndWithBracket()) { + whereClause.append(")"); + } + + // 添加连接符(AND/OR) + if (conditionIndex < conditions.size() - 1) { + whereClause.append(" ").append(condition.getConcatFactor()).append(" "); + } + conditionIndex++; + } + + return whereClause.toString(); + } + + /** + * 校验字段名合法性(防止 SQL 注入) + */ + private String validateFieldName(String fieldName) { + if (!fieldName.matches("^[a-zA-Z_][a-zA-Z0-9_]*$")) { + throw new IllegalArgumentException("非法字段名: " + fieldName); + } + return fieldName; + } + + /** + * 解析运算符映射(eq -> =, lt -> < 等) + */ + private String parseOperator(ClauseFactor factor) { + if(factor == null) { + return "="; + } + switch (factor) { + case EQ: return "="; + case GT: return ">"; + case GE: return ">="; + case LT: return "<"; + case LE: return "<="; + case LIKE: return "LIKE"; + case NULL: return "IS NULL"; // 空值判断 + case NOT_NULL: return "IS NOT NULL"; // 非空判断 + default: throw new UnsupportedOperationException("不支持的运算符: " + factor); + } + } + + +} \ No newline at end of file diff --git a/v5/apps-customize/src/main/java/com/seeyon/apps/src_saomaoyi/utils/FormExportUtil.java b/v5/apps-customize/src/main/java/com/seeyon/apps/src_saomaoyi/utils/FormExportUtil.java new file mode 100644 index 0000000..67e6d57 --- /dev/null +++ b/v5/apps-customize/src/main/java/com/seeyon/apps/src_saomaoyi/utils/FormExportUtil.java @@ -0,0 +1,84 @@ +package com.seeyon.apps.src_saomaoyi.utils; + +import com.seeyon.v3x.services.form.bean.RecordExport; +import com.seeyon.v3x.services.form.bean.SubordinateFormExport; +import com.seeyon.v3x.services.form.bean.ValueExport; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Set; + +//创建无流程表单数据处理工具类 +public class FormExportUtil { + + /** + * 设置主表信息 + * @param map 设置主表字段。Map<主表显示名称,主表数据> + * @return + */ + public List setFormValue(Map map ){ +// 创建返回值对象 + List valueExports = new ArrayList(); + ValueExport valueExport ; +// 获取参数信息(显示名称) + Set keys = map.keySet(); + if(keys.size()>0) { +// 对控件赋值 + for (String key : keys) { + if(map.get(key) != null ){ + valueExport = new ValueExport(); + valueExport.setDisplayName(key); + valueExport.setValue(map.get(key).toString()); + valueExports.add(valueExport); + } + System.out.println(key+":"+map.get(key)); + } + } + return valueExports; + } + + /** + * 设置从表信息 + * @param lists 设置主表字段。List> + */ + public List setSubordinateFormValue(List> lists){ + List subordinateFormExports = new ArrayList(); + SubordinateFormExport subordinateFormExport = new SubordinateFormExport(); + List recordExports = new ArrayList(); + List valueExports; + RecordExport recordExport; + for(int i = 0 ; i < lists.size() ; i++) { + recordExport = new RecordExport(); + valueExports = setFormValue(lists.get(i)); + recordExport.setRecord(valueExports); + recordExports.add(recordExport); + } + subordinateFormExport.setValues(recordExports); + subordinateFormExports.add(subordinateFormExport); + + return subordinateFormExports; + } + + public List setAllSubordinateFormValue(List> lists){ + List subordinateFormExports = new ArrayList(); + for (Map list : lists) { + SubordinateFormExport subordinateFormExport = new SubordinateFormExport(); + List recordExports = new ArrayList(); + for (String key : list.keySet()) { + List> columns = (List>) list.get(key); + for(int i = 0 ; i < columns.size() ; i++) { + List valueExports = setFormValue(columns.get(i)); + RecordExport recordExport = new RecordExport(); + recordExport.setRecord(valueExports); + recordExports.add(recordExport); + } + } + subordinateFormExport.setValues(recordExports); + subordinateFormExports.add(subordinateFormExport); + } + return subordinateFormExports; + } + + +} diff --git a/v5/apps-customize/src/main/java/com/seeyon/apps/src_saomaoyi/utils/FormFieldVo.java b/v5/apps-customize/src/main/java/com/seeyon/apps/src_saomaoyi/utils/FormFieldVo.java new file mode 100644 index 0000000..16e3b51 --- /dev/null +++ b/v5/apps-customize/src/main/java/com/seeyon/apps/src_saomaoyi/utils/FormFieldVo.java @@ -0,0 +1,22 @@ +package com.seeyon.apps.src_saomaoyi.utils; + +public class FormFieldVo { + private String displayName; + private Object value; + + public String getDisplayName() { + return displayName; + } + + public void setDisplayName(String displayName) { + this.displayName = displayName; + } + + public Object getValue() { + return value; + } + + public void setValue(Object value) { + this.value = value; + } +} diff --git a/v5/apps-customize/src/main/java/com/seeyon/apps/src_saomaoyi/utils/FormUpdateField.java b/v5/apps-customize/src/main/java/com/seeyon/apps/src_saomaoyi/utils/FormUpdateField.java new file mode 100644 index 0000000..af70603 --- /dev/null +++ b/v5/apps-customize/src/main/java/com/seeyon/apps/src_saomaoyi/utils/FormUpdateField.java @@ -0,0 +1,57 @@ +package com.seeyon.apps.src_saomaoyi.utils; + +public class FormUpdateField { + private String display; + private String fieldName; + private Object value; + + public FormUpdateField(Object value) { + this.value = value; + } + + public FormUpdateField() { + } + + public static FormUpdateField build() { + return new FormUpdateField(); + } + + public FormUpdateField display(String display) { + this.display = display; + return this; + } + + public FormUpdateField value(String value) { + this.value = value; + return this; + } + + public FormUpdateField fieldName(String fieldName) { + this.fieldName = fieldName; + return this; + } + + public Object getValue() { + return value; + } + + public void setValue(Object value) { + this.value = value; + } + + public String getDisplay() { + return display; + } + + public void setDisplay(String display) { + this.display = display; + } + + public String getFieldName() { + return fieldName; + } + + public void setFieldName(String fieldName) { + this.fieldName = fieldName; + } +} diff --git a/v5/apps-customize/src/main/java/com/seeyon/apps/src_saomaoyi/utils/FormWhereCondition.java b/v5/apps-customize/src/main/java/com/seeyon/apps/src_saomaoyi/utils/FormWhereCondition.java new file mode 100644 index 0000000..0415821 --- /dev/null +++ b/v5/apps-customize/src/main/java/com/seeyon/apps/src_saomaoyi/utils/FormWhereCondition.java @@ -0,0 +1,121 @@ +package com.seeyon.apps.src_saomaoyi.utils; + +public class FormWhereCondition { + private String display; + private String fieldName; //字段名 + private Object value; //值 + private ClauseFactor clauseFactor; //条件因子 eq lt gt not_null null + private ClauseFactor concatFactor = ClauseFactor.AND; //拼接因子 + private boolean startWithBracket = false; //是否以括号开头生成子条件 + private boolean endWithBracket = false; //是否以括号结尾结束子条件 + private String index; + + public FormWhereCondition() { + } + + public String getDisplay() { + return display; + } + + public void setDisplay(String display) { + this.display = display; + } + + public static FormWhereCondition build() { + return new FormWhereCondition(); + } + + public FormWhereCondition display(String display) { + this.display = display; + return this; + } + public FormWhereCondition value(Object value) { + this.value = value; + return this; + } + public FormWhereCondition clauseFactor(ClauseFactor clauseFactor) { + this.clauseFactor = clauseFactor; + return this; + } + public FormWhereCondition index(String index) { + this.index = index; + return this; + } + + public FormWhereCondition startWithBracket(boolean startWithBracket) { + this.startWithBracket = startWithBracket; + return this; + } + + public FormWhereCondition endWithBracket(boolean endWithBracket) { + this.endWithBracket = endWithBracket; + return this; + } + + public FormWhereCondition concatFactor(ClauseFactor concatFactor) { + this.concatFactor = concatFactor; + return this; + } + + + public FormWhereCondition(Object value, ClauseFactor clauseFactor) { + this.value = value; + this.clauseFactor = clauseFactor; + } + + public boolean isStartWithBracket() { + return startWithBracket; + } + + public void setStartWithBracket(boolean startWithBracket) { + this.startWithBracket = startWithBracket; + } + + public String getFieldName() { + return fieldName; + } + + public void setFieldName(String fieldName) { + this.fieldName = fieldName; + } + + public Object getValue() { + return value; + } + + public void setValue(Object value) { + this.value = value; + } + + public ClauseFactor getClauseFactor() { + return clauseFactor; + } + + public void setClauseFactor(ClauseFactor clauseFactor) { + this.clauseFactor = clauseFactor; + } + + public ClauseFactor getConcatFactor() { + return concatFactor; + } + + public void setConcatFactor(ClauseFactor concatFactor) { + this.concatFactor = concatFactor; + } + + public String getIndex() { + return index; + } + + public void setIndex(String index) { + this.index = index; + } + + public boolean isEndWithBracket() { + return endWithBracket; + } + + public void setEndWithBracket(boolean endWithBracket) { + this.endWithBracket = endWithBracket; + } +} diff --git a/v5/apps-customize/src/main/java/com/seeyon/apps/src_saomaoyi/utils/HttpClient.java b/v5/apps-customize/src/main/java/com/seeyon/apps/src_saomaoyi/utils/HttpClient.java new file mode 100644 index 0000000..fe865a2 --- /dev/null +++ b/v5/apps-customize/src/main/java/com/seeyon/apps/src_saomaoyi/utils/HttpClient.java @@ -0,0 +1,417 @@ +package com.seeyon.apps.src_saomaoyi.utils; + +import org.apache.http.HttpEntity; +import org.apache.http.NameValuePair; +import org.apache.http.client.entity.UrlEncodedFormEntity; +import org.apache.http.client.methods.*; +import org.apache.http.entity.ContentType; +import org.apache.http.entity.StringEntity; +import org.apache.http.entity.mime.HttpMultipartMode; +import org.apache.http.entity.mime.MultipartEntityBuilder; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.message.BasicNameValuePair; +import org.apache.http.util.EntityUtils; + +import java.io.*; +import java.nio.charset.Charset; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * @ClassName: HttpClient + * @Description: HTTP请求工具类 + * @Author: GiikJc + * @Date: 2022/7/12 15:03 + */ + +/** + * 发送Get请求:HttpResponse httpGet(String url,Map headers,String encode) + *发送Post请求,同表单Post提交:HttpResponse httpPostForm(String url,Map params, Map headers,String encode) + *发送Post Raw请求:HttpResponse httpPostRaw(String url,String stringJson,Map headers, String encode) + *发送Put Raw请求:HttpResponse httpPutRaw(String url,String stringJson,Map headers, String encode) + *发送Delete请求:HttpResponse httpDelete(String url,Map headers,String encode) + */ +public class HttpClient { + + + /** + * 发送 HTTP GET 请求下载文件 + * @param url 下载文件的 URL + * @param headers 请求头 + * @param savePath 文件保存的路径 + * @param encode 文件内容的编码 + * @return 下载成功返回 true,失败返回 false + */ + public static boolean httpDownloadFile(String url, Map headers, String savePath, String encode) { + if (encode == null) { + encode = "utf-8"; // 默认字符编码 + } + + CloseableHttpClient httpClient = null; + CloseableHttpResponse httpResponse = null; + InputStream inputStream = null; + OutputStream outputStream = null; + + try { + // 创建 HttpClient 实例 + httpClient = HttpClients.createDefault(); + HttpGet httpGet = new HttpGet(url); + + // 设置请求头 + if (headers != null && headers.size() > 0) { + for (Map.Entry entry : headers.entrySet()) { + httpGet.setHeader(entry.getKey(), entry.getValue()); + } + } + + // 执行请求 + httpResponse = httpClient.execute(httpGet); + HttpEntity entity = httpResponse.getEntity(); + + // 检查响应状态码 + if (httpResponse.getStatusLine().getStatusCode() == 200) { + inputStream = entity.getContent(); + + // 创建输出流,将文件保存到本地 + outputStream = new FileOutputStream(savePath); + + // 设置缓冲区 + byte[] buffer = new byte[4096]; + int bytesRead; + while ((bytesRead = inputStream.read(buffer)) != -1) { + outputStream.write(buffer, 0, bytesRead); + } + + // 文件下载成功 + return true; + } else { + System.out.println("Download failed, HTTP error code: " + httpResponse.getStatusLine().getStatusCode()); + return false; + } + } catch (Exception e) { + e.printStackTrace(); + return false; + } finally { + try { + if (inputStream != null) { + inputStream.close(); + } + if (outputStream != null) { + outputStream.close(); + } + if (httpResponse != null) { + httpResponse.close(); + } + if (httpClient != null) { + httpClient.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + /** + * 发送http get请求 + */ + public static String httpGet(String url,Map headers,String encode){ + + if(encode == null){ + encode = "utf-8"; + } + CloseableHttpResponse httpResponse = null; + CloseableHttpClient closeableHttpClient = null; + String content = null; + //since 4.3 不再使用 DefaultHttpClient + try { + closeableHttpClient = HttpClientBuilder.create().build(); + HttpGet httpGet = new HttpGet(url); + //设置header + if (headers != null && headers.size() > 0) { + for (Map.Entry entry : headers.entrySet()) { + httpGet.setHeader(entry.getKey(),entry.getValue()); + } + } + + httpResponse = closeableHttpClient.execute(httpGet); + HttpEntity entity = httpResponse.getEntity(); + content = EntityUtils.toString(entity, encode); + } catch (Exception e) { + e.printStackTrace(); + }finally{ + try { + httpResponse.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + try { //关闭连接、释放资源 + closeableHttpClient.close(); + } catch (IOException e) { + e.printStackTrace(); + } + return content; + } + /** + * 发送 http post 请求,参数以form表单键值对的形式提交。 + */ + public static String httpPostForm(String url,Map params, Map headers,String encode){ + + if(encode == null){ + encode = "utf-8"; + } + + String content = null; + CloseableHttpResponse httpResponse = null; + CloseableHttpClient closeableHttpClient = null; + try { + + closeableHttpClient = HttpClients.createDefault(); + HttpPost httpost = new HttpPost(url); + + //设置header + if (headers != null && headers.size() > 0) { + for (Map.Entry entry : headers.entrySet()) { + httpost.setHeader(entry.getKey(),entry.getValue()); + } + } + //组织请求参数 + List paramList = new ArrayList (); + if(params != null && params.size() > 0){ + Set keySet = params.keySet(); + for(String key : keySet) { + paramList.add(new BasicNameValuePair(key, params.get(key))); + } + } + httpost.setEntity(new UrlEncodedFormEntity(paramList, encode)); + + + httpResponse = closeableHttpClient.execute(httpost); + HttpEntity entity = httpResponse.getEntity(); + content = EntityUtils.toString(entity, encode); + } catch (Exception e) { + e.printStackTrace(); + }finally{ + try { + httpResponse.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + try { //关闭连接、释放资源 + closeableHttpClient.close(); + } catch (IOException e) { + e.printStackTrace(); + } + return content; + } + + /** + * 发送 http post 请求,参数以原生字符串进行提交 + * @param url + * @param encode + * @return + */ + public static String httpPostRaw(String url,String stringJson,Map headers, String encode){ + if(encode == null){ + encode = "utf-8"; + } + String content = null; + CloseableHttpResponse httpResponse = null; + CloseableHttpClient closeableHttpClient = null; + try { + + //HttpClients.createDefault()等价于 HttpClientBuilder.create().build(); + closeableHttpClient = HttpClients.createDefault(); + HttpPost httpost = new HttpPost(url); + + //设置header + httpost.setHeader("Content-type", "application/json"); + if (headers != null && headers.size() > 0) { + for (Map.Entry entry : headers.entrySet()) { + httpost.setHeader(entry.getKey(),entry.getValue()); + } + } + //组织请求参数 + StringEntity stringEntity = new StringEntity(stringJson, encode); + httpost.setEntity(stringEntity); + + + //响应信息 + httpResponse = closeableHttpClient.execute(httpost); + HttpEntity entity = httpResponse.getEntity(); + content = EntityUtils.toString(entity, encode); + } catch (Exception e) { + e.printStackTrace(); + }finally{ + try { + httpResponse.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + try { //关闭连接、释放资源 + closeableHttpClient.close(); + } catch (IOException e) { + e.printStackTrace(); + } + return content; + } + + /** + * 发送 http put 请求,参数以原生字符串进行提交 + * @param url + * @param encode + * @return + */ + public static String httpPutRaw(String url,String stringJson,Map headers, String encode){ + if(encode == null){ + encode = "utf-8"; + } + CloseableHttpResponse httpResponse = null; + CloseableHttpClient closeableHttpClient = null; + String content = null; + //since 4.3 不再使用 DefaultHttpClient + try { + + //HttpClients.createDefault()等价于 HttpClientBuilder.create().build(); + closeableHttpClient = HttpClients.createDefault(); + HttpPut httpput = new HttpPut(url); + + //设置header + httpput.setHeader("Content-type", "application/json"); + if (headers != null && headers.size() > 0) { + for (Map.Entry entry : headers.entrySet()) { + httpput.setHeader(entry.getKey(),entry.getValue()); + } + } + //组织请求参数 + StringEntity stringEntity = new StringEntity(stringJson, encode); + httpput.setEntity(stringEntity); + //响应信息 + httpResponse = closeableHttpClient.execute(httpput); + HttpEntity entity = httpResponse.getEntity(); + content = EntityUtils.toString(entity, encode); + } catch (Exception e) { + e.printStackTrace(); + }finally{ + try { + httpResponse.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + try { + closeableHttpClient.close(); //关闭连接、释放资源 + } catch (IOException e) { + e.printStackTrace(); + } + return content; + } + /** + * 发送http delete请求 + */ + public static String httpDelete(String url,Map headers,String encode){ + if(encode == null){ + encode = "utf-8"; + } + String content = null; + CloseableHttpResponse httpResponse = null; + CloseableHttpClient closeableHttpClient = null; + try { + //since 4.3 不再使用 DefaultHttpClient + closeableHttpClient = HttpClientBuilder.create().build(); + HttpDelete httpdelete = new HttpDelete(url); + //设置header + if (headers != null && headers.size() > 0) { + for (Map.Entry entry : headers.entrySet()) { + httpdelete.setHeader(entry.getKey(),entry.getValue()); + } + } + + httpResponse = closeableHttpClient.execute(httpdelete); + HttpEntity entity = httpResponse.getEntity(); + content = EntityUtils.toString(entity, encode); + } catch (Exception e) { + e.printStackTrace(); + }finally{ + try { + httpResponse.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + try { //关闭连接、释放资源 + closeableHttpClient.close(); + } catch (IOException e) { + e.printStackTrace(); + } + return content; + } + + /** + * 发送 http post 请求,支持文件上传 + */ + public static String httpPostFormMultipart(String url,Map params, List files,Map headers,String encode){ + if(encode == null){ + encode = "utf-8"; + } + CloseableHttpResponse httpResponse = null; + CloseableHttpClient closeableHttpClient = null; + String content = null; + //since 4.3 不再使用 DefaultHttpClient + try { + + closeableHttpClient = HttpClients.createDefault(); + HttpPost httpost = new HttpPost(url); + + //设置header + if (headers != null && headers.size() > 0) { + for (Map.Entry entry : headers.entrySet()) { + httpost.setHeader(entry.getKey(),entry.getValue()); + } + } + MultipartEntityBuilder mEntityBuilder = MultipartEntityBuilder.create(); + mEntityBuilder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE); + mEntityBuilder.setCharset(Charset.forName(encode)); + + // 普通参数 + ContentType contentType = ContentType.create("text/plain",Charset.forName(encode));//解决中文乱码 + if (params != null && params.size() > 0) { + Set keySet = params.keySet(); + for (String key : keySet) { + mEntityBuilder.addTextBody(key, params.get(key),contentType); + } + } + //二进制参数 + if (files != null && files.size() > 0) { + for (File file : files) { + mEntityBuilder.addBinaryBody("file", file); + } + } + httpost.setEntity(mEntityBuilder.build()); + httpResponse = closeableHttpClient.execute(httpost); + HttpEntity entity = httpResponse.getEntity(); + content = EntityUtils.toString(entity, encode); + } catch (Exception e) { + e.printStackTrace(); + }finally{ + try { + httpResponse.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + try { //关闭连接、释放资源 + closeableHttpClient.close(); + } catch (IOException e) { + e.printStackTrace(); + } + return content; + } + +} diff --git a/v5/apps-customize/src/main/java/com/seeyon/ctp/rest/resources/HandleSaoMiaoYiImgResource.java b/v5/apps-customize/src/main/java/com/seeyon/ctp/rest/resources/HandleSaoMiaoYiImgResource.java new file mode 100644 index 0000000..4a8138b --- /dev/null +++ b/v5/apps-customize/src/main/java/com/seeyon/ctp/rest/resources/HandleSaoMiaoYiImgResource.java @@ -0,0 +1,57 @@ +package com.seeyon.ctp.rest.resources; + +import com.seeyon.apps.src_saomaoyi.invoice.InvoiceImgSaveService; +import com.seeyon.ctp.common.AppContext; +import org.springframework.web.multipart.MultipartFile; +import org.springframework.web.multipart.MultipartHttpServletRequest; +import org.springframework.web.multipart.commons.CommonsMultipartResolver; + +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.Consumes; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.Response; +import java.io.InputStream; +import java.util.Iterator; + +@Path("/saomiaoyi") +@Produces({"application/json", "application/xml"}) +public class HandleSaoMiaoYiImgResource extends BaseResource { + + private InvoiceImgSaveService invoiceImgSaveService = (InvoiceImgSaveService) AppContext.getBean("invoiceImgSaveServiceImpl"); + + @Context + HttpServletRequest req; + + @POST + @Path("/fileSave") + @Produces({"application/json"}) + @Consumes({"multipart/form-data"}) + public Response fileSave() { + try { + CommonsMultipartResolver resolver = new CommonsMultipartResolver(); + resolver.setDefaultEncoding("utf-8"); + if (resolver.isMultipart(req)) { + MultipartHttpServletRequest multipartRequest = resolver.resolveMultipart(req); + + // 获取所有文件名 + Iterator fileNames = multipartRequest.getFileNames(); + + while (fileNames.hasNext()) { + String name = fileNames.next(); + MultipartFile file = multipartRequest.getFile(name); + if (file != null && !file.isEmpty()) { + InputStream inputStream = file.getInputStream(); + invoiceImgSaveService.saveInvoiceImg(inputStream); + inputStream.close(); + } + } + } + return success(""); + }catch (Exception e) { + return fail(e.getMessage()); + } + } +} diff --git a/v5/apps-customize/src/main/test/TestB.java b/v5/apps-customize/src/main/test/TestB.java new file mode 100644 index 0000000..2199405 --- /dev/null +++ b/v5/apps-customize/src/main/test/TestB.java @@ -0,0 +1,8 @@ +import com.seeyon.apps.src_saomaoyi.invoice.InvoiceImgSaveServiceImpl; + +public class TestB { + + public static void main(String[] args) { + InvoiceImgSaveServiceImpl saveService = new InvoiceImgSaveServiceImpl(); + } +} diff --git a/v5/apps-customize/src/main/webapp/WEB-INF/cfgHome/plugin/src_saomiaoyi/pluginCfg.xml b/v5/apps-customize/src/main/webapp/WEB-INF/cfgHome/plugin/src_saomiaoyi/pluginCfg.xml new file mode 100644 index 0000000..5f6a29f --- /dev/null +++ b/v5/apps-customize/src/main/webapp/WEB-INF/cfgHome/plugin/src_saomiaoyi/pluginCfg.xml @@ -0,0 +1,6 @@ + + + src_saomiaoyi + 扫描仪 + 20251201 + \ No newline at end of file diff --git a/v5/apps-customize/src/main/webapp/WEB-INF/cfgHome/plugin/src_saomiaoyi/spring/spring-bean.xml b/v5/apps-customize/src/main/webapp/WEB-INF/cfgHome/plugin/src_saomiaoyi/spring/spring-bean.xml new file mode 100644 index 0000000..19d4cd3 --- /dev/null +++ b/v5/apps-customize/src/main/webapp/WEB-INF/cfgHome/plugin/src_saomiaoyi/spring/spring-bean.xml @@ -0,0 +1,12 @@ + + + + + \ No newline at end of file diff --git a/v5/apps-customize/src/main/webapp/WEB-INF/cfgHome/plugin/src_saomiaoyi/spring/spring-quartz.xml b/v5/apps-customize/src/main/webapp/WEB-INF/cfgHome/plugin/src_saomiaoyi/spring/spring-quartz.xml new file mode 100644 index 0000000..f701d88 --- /dev/null +++ b/v5/apps-customize/src/main/webapp/WEB-INF/cfgHome/plugin/src_saomiaoyi/spring/spring-quartz.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/v5/apps-customize/src/main/webapp/WEB-INF/cfgHome/plugin/src_saomiaoyi/spring/spring.xml b/v5/apps-customize/src/main/webapp/WEB-INF/cfgHome/plugin/src_saomiaoyi/spring/spring.xml new file mode 100644 index 0000000..fad8443 --- /dev/null +++ b/v5/apps-customize/src/main/webapp/WEB-INF/cfgHome/plugin/src_saomiaoyi/spring/spring.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/v5/apps-customize/src/main/webapp/apps_res/cap/customCtrlResources/saomiaoyiBtnResources/css/img/icon16.png b/v5/apps-customize/src/main/webapp/apps_res/cap/customCtrlResources/saomiaoyiBtnResources/css/img/icon16.png new file mode 100644 index 0000000..e43def3 Binary files /dev/null and b/v5/apps-customize/src/main/webapp/apps_res/cap/customCtrlResources/saomiaoyiBtnResources/css/img/icon16.png differ diff --git a/v5/apps-customize/src/main/webapp/apps_res/cap/customCtrlResources/saomiaoyiBtnResources/css/saomiaoyiBtn.css b/v5/apps-customize/src/main/webapp/apps_res/cap/customCtrlResources/saomiaoyiBtnResources/css/saomiaoyiBtn.css new file mode 100644 index 0000000..e5c4ae0 --- /dev/null +++ b/v5/apps-customize/src/main/webapp/apps_res/cap/customCtrlResources/saomiaoyiBtnResources/css/saomiaoyiBtn.css @@ -0,0 +1,36 @@ +.customButton_class_box { + width: 35%; + line-height: 24px; + height:24px; + color: #1f85ec; + cursor: pointer; + font-family: "Microsoft YaHei"!important; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; + word-break:keep-all; + box-sizing: border-box; + -webkit-box-sizing : border-box; + -moz-box-sizing : border-box; + text-align: center; + outline: none; + border: 1px solid #1f85ec; + background-color: #fff; + border-radius: 15px; + -webkit-border-radius: 15px; + -moz-border-radius: 15px; +} +.customInputArea{ + width: 65%; + height:auto; + color: #1f85ec; + font-family: "Microsoft YaHei"!important; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; + word-break:keep-all; +} +.customButton_box_content{ + width: 100%; + height: auto; +} diff --git a/v5/apps-customize/src/main/webapp/apps_res/cap/customCtrlResources/saomiaoyiBtnResources/html/saomiaoyi.html b/v5/apps-customize/src/main/webapp/apps_res/cap/customCtrlResources/saomiaoyiBtnResources/html/saomiaoyi.html new file mode 100644 index 0000000..e916b56 --- /dev/null +++ b/v5/apps-customize/src/main/webapp/apps_res/cap/customCtrlResources/saomiaoyiBtnResources/html/saomiaoyi.html @@ -0,0 +1,16 @@ + + + + + 富士通扫描仪 + + + + + + + + + + \ No newline at end of file diff --git a/v5/apps-customize/src/main/webapp/apps_res/cap/customCtrlResources/saomiaoyiBtnResources/html/saomiaoyiImg.html b/v5/apps-customize/src/main/webapp/apps_res/cap/customCtrlResources/saomiaoyiBtnResources/html/saomiaoyiImg.html new file mode 100644 index 0000000..e916b56 --- /dev/null +++ b/v5/apps-customize/src/main/webapp/apps_res/cap/customCtrlResources/saomiaoyiBtnResources/html/saomiaoyiImg.html @@ -0,0 +1,16 @@ + + + + + 富士通扫描仪 + + + + + + + + + + \ No newline at end of file diff --git a/v5/apps-customize/src/main/webapp/apps_res/cap/customCtrlResources/saomiaoyiBtnResources/js/img.js b/v5/apps-customize/src/main/webapp/apps_res/cap/customCtrlResources/saomiaoyiBtnResources/js/img.js new file mode 100644 index 0000000..cdc9d38 --- /dev/null +++ b/v5/apps-customize/src/main/webapp/apps_res/cap/customCtrlResources/saomiaoyiBtnResources/js/img.js @@ -0,0 +1,354 @@ +(function(_self, factory) { + var nameSpace = 'customBtn_1992789877417263104'; + + if (!window[nameSpace] && typeof factory === 'function') { + var Builder = factory(); + window[nameSpace] = { + initBtn : {} + }; + /** + * 初始化方法 + */ + console.log("初始化") + window[nameSpace].init = function(el, options) { + var identification = Math.floor(Math.round() * 10000000000) + .toString(); + window[nameSpace].initBtn[identification] = new Builder(el, + options, _self, identification); + } + } +}) + ( + window, + function() { + /** + * js,css文件加载方法 + */ + var dynamicLoading = { + css : function(path, name, callBk) { + if (!path || path.length === 0) { + throw new Error('argument "path" is required !'); + } + var head = document.getElementsByTagName('head')[0]; + var link = document.createElement('link'); + link.href = path; + link.rel = 'stylesheet'; + link.type = 'text/css'; + link.setAttribute('data-name', name); + link.onload = function() { + callBk(); + } + head.appendChild(link); + }, + insertCss : function(innerTexts, name) { + var head = document.getElementsByTagName('head')[0]; + var style = document.createElement('style'); + style.type = 'text/css'; + style.setAttribute('data-name', name); + try { + style.appendChild(document + .createTextNode(innerTexts)); + } catch (ex) { + style.styleSheet.cssText = innerTexts;// 针对IE + } + head.appendChild(style); + }, + checkCss : function(name) { + var styleList = document + .getElementsByTagName('style'); + for (var i = 0; i < styleList.length; i++) { + if (styleList[i].getAttribute('data-name') === name) + return true; + } + return false; + }, + js : function(path, callBk) { + if (!path || path.length === 0) { + throw new Error('argument "path" is required !'); + } + var head = document.getElementsByTagName('head')[0]; + var script = document.createElement('script'); + script.src = path; + script.type = 'text/javascript'; + script.onload = function() { + callBk(); + } + head.appendChild(script); + }, + checkJs : function(name) { + var scriptList = document + .getElementsByTagName('script'); + for (var i = 0; i < scriptList.length; i++) { + if (scriptList[i].getAttribute('data-name') === name) + return true; + } + return false; + }, + } + /** + * 浏览器 + */ + function myBrowser() { + var userAgent = navigator.userAgent; // 取得浏览器的userAgent字符串 + var isOpera = userAgent.indexOf("Opera") > -1; + if (isOpera) { // 判断是否Opera浏览器 + return "Opera" + } + ; + if (userAgent.indexOf("Firefox") > -1) { // 判断是否Firefox浏览器 + return "FF"; + } + ; + if (userAgent.indexOf("Chrome") > -1) { + return "Chrome"; + } + ; + if (userAgent.indexOf("Safari") > -1) { // 判断是否Safari浏览器 + return "Safari"; + } + ; + if (userAgent.indexOf("compatible") > -1 + && userAgent.indexOf("MSIE") > -1 && !isOpera) { // 判断是否IE浏览器 + return "IE"; + } + ; + } + /** + * 定义标签打印按钮的构造函数 + * + * @param {*} + * options + * @param {*} + * _self + */ + function labelPrintingBtn(el, options, _self, + identification) { + var self = this; + self.window_self = _self; + self.el = el; + self.identification = identification; + // 解析传进来的数据 + self.initParams(options); + // 处理挂载 + self.initBtn(el); + // 销毁自己 + self.beforeDestroy = function() { + self = null; + } + } + /** + * 构造函数的原型方法 + */ + labelPrintingBtn.prototype = { + initParams : function(options) { + console.log("初始化") + this.place = options.place; + this.rowData = options.rowData; + this.data = options.data; + }, + initBtn : function(el) { + /** + * 挂载dom初始化处理 + */ + var innerTexts = '.labelPrintingBtnHandler {' + + 'background-color: rgba(0,0,0,0);' + + 'font-family: "Ping Fang SC", "Microsoft YaHei", Arial, Helvetica, sans-serif, "SimSun";' + + 'cursor: pointer;' + + 'white-space : nowrap;' + + 'border: 0;' + + 'overflow: hidden;' + + 'text-overflow: ellipsis;' + + '}' + + '.labelPrintingBtnBox { box-sizing: border-box; cursor: pointer; outline: none; font-family: inherit; white-space: nowrap;display: inline-block; margin-top: 5px; vertical-align: middle; margin-right: 5px;' + + ' background-color: #fff; border: 1px solid #d4d4d4; color: #666;font-size: 14px; line-height: 28px; border-radius: 15px; height: 30px;}' + + '.labelPrintingBtnBox:hover{ border-color: #1f85ec; }' + + '.labelPrintingBtnRow{color: #1f85ec;}' + + '.labelPrintingBtnRow:hover{color : #479bf3}' + + '.labelPrintingBtnLi{color : #333}' + + '.labelPrintingBtnLi:hover{color : #fff}'; + if (!dynamicLoading.checkCss('labelPrintingBtn')) { + dynamicLoading.insertCss(innerTexts, + 'labelPrintingBtn'); + } + // 挂载dom + this.appendDom(el); + }, + appendDom : function(el) { + var self = this; + var labelPrint = document.createElement('div'), labelPrintToolbar, labelPrintIcon; + // 对代码片段进行配置 + el.appendChild(labelPrint); + // 根据不同位置渲染按钮 + switch (this.place) { + case 'toolbar': + labelPrint.parentNode.setAttribute('class', + 'labelPrintingBtnBox'); + labelPrint.style.padding = '0 14px'; + // 加入icon + labelPrintIcon = document.createElement('i'); + labelPrintIcon.setAttribute('class', + 'CAP cap-icon-dayin'); + labelPrintIcon.style.color = '#C3AF1C'; + labelPrint.appendChild(labelPrintIcon); + // 加入name信息 + labelPrintToolbar = document + .createElement('span'); + labelPrintToolbar.innerHTML = this.data + && this.data.name ? this.data.name : ''; + labelPrintToolbar.style.paddingLeft = '3px'; + labelPrint.appendChild(labelPrintToolbar); + break; + case 'li': + labelPrint.innerHTML = this.data + && this.data.name ? this.data.name : ''; + labelPrint + .setAttribute('class', + 'labelPrintingBtnLi labelPrintingBtnHandler') + break; + case 'row': + labelPrint.innerHTML = this.data + && this.data.name ? this.data.name : ''; + labelPrint + .setAttribute('class', + 'labelPrintingBtnRow labelPrintingBtnHandler') + break; + default: + } + labelPrint.onclick = function() { + switch (self.place) { + case 'toolbar': + // 点击执行对应的操作 + self.implementClick(); + break; + case 'li': + case 'row': + // 点击执行对应的操作 + self.implementClick(self.rowData); + break; + default: + } + + } + // 阻止数据污染 + labelPrint.parentNode.onclick = function(e) { + e.stopPropagation(); + } + }, + // 执行点击事件 + implementClick : function(rowData) { + var self = this; + var datas; + if (!rowData && window.extendApi + && window.extendApi.getChooseId) { + datas = window.extendApi.getChooseId(); + } else { + datas = rowData.id; + } + // 获取模版id + this.handlerLogic(datas); + }, + // 点击逻辑执行 + handlerLogic : function(rowData) { + this.getImages(); + }, + getImages: function() { + var batchCode = window.localStorage.getItem('saomiaoyi'); + var saoMiaoYiApiBaseUrl = "http://localhost:8080"; + + // 1. 阻塞获取图片列表 + var xhr = new XMLHttpRequest(); + xhr.open("GET", saoMiaoYiApiBaseUrl + "/jControls/getImage", false); + xhr.setRequestHeader("batchNumber", batchCode); + xhr.send(null); + + if (xhr.status !== 200) { + console.error("getImage 请求失败", xhr.status); + return; + } + + var res = JSON.parse(xhr.responseText); + var imgs = res.data.imgList || []; + + // 2. 逐张上传(阻塞) + for (var i = 0; i < imgs.length; i++) { + this.uploadImage(imgs[i],i) + } + var xhr2 = new XMLHttpRequest(); + xhr2.open("GET", saoMiaoYiApiBaseUrl + "/jControls/getStop", false); + xhr2.send(null); + + if (xhr2.status !== 200) { + console.error("getImage 请求失败", xhr.status); + return; + } + + }, + base64ToBlob: function(base64String) { + // 如果包含 "data:" 则按 dataURL 解析 + if (base64String.startsWith("data:")) { + const arr = base64String.split(','); + const pre = arr[0]; + const base64Data = arr[1]; + + // 获取 MIME 类型 + let mime = "application/octet-stream"; + const mimeMatch = pre.match(/data:(.*?);base64/); + if (mimeMatch && mimeMatch[1]) { + mime = mimeMatch[1]; + } + + const byteString = atob(base64Data); + const len = byteString.length; + const u8arr = new Uint8Array(len); + + for (let i = 0; i < len; i++) { + u8arr[i] = byteString.charCodeAt(i); + } + + return new Blob([u8arr], { type: mime }); + } + + // ---- 如果没有 data: 前缀,按纯 Base64 解码 ---- + const byteString = atob(base64String); + const len = byteString.length; + const u8arr = new Uint8Array(len); + + for (let i = 0; i < len; i++) { + u8arr[i] = byteString.charCodeAt(i); + } + + // 默认二进制流类型 + return new Blob([u8arr], { type: "application/octet-stream" }); + }, + + // 如果想要 File 对象 + base64ToFile: function(base64, filename) { + const blob = this.base64ToBlob(base64); + return new File([blob], filename, { type: blob.type }); + }, + + uploadImage: function(base64, filename) { + const file = this.base64ToFile(base64, filename); + + const formData = new FormData(); + formData.append('file', file); + var apiBaseUrl = window.location.origin; + const xhr = new XMLHttpRequest(); + xhr.open('POST', apiBaseUrl + '/seeyon/rest/saomiaoyi/fileSave', true); // 可以改成 false 同步 + xhr.onreadystatechange = function() { + if (xhr.readyState === 4) { + if (xhr.status === 200) { + console.log('上传成功:', xhr.responseText); + } else { + console.error('上传失败:', xhr.status, xhr.responseText); + } + } + }; + xhr.send(formData); + } + }; + /** + * 返回值 + */ + return labelPrintingBtn; + }); \ No newline at end of file diff --git a/v5/apps-customize/src/main/webapp/apps_res/cap/customCtrlResources/saomiaoyiBtnResources/js/init.js b/v5/apps-customize/src/main/webapp/apps_res/cap/customCtrlResources/saomiaoyiBtnResources/js/init.js new file mode 100644 index 0000000..9255e5a --- /dev/null +++ b/v5/apps-customize/src/main/webapp/apps_res/cap/customCtrlResources/saomiaoyiBtnResources/js/init.js @@ -0,0 +1,291 @@ +(function(_self, factory) { + var nameSpace = 'customBtn_1992789877417263105'; + if (!window[nameSpace] && typeof factory === 'function') { + var Builder = factory(); + window[nameSpace] = { + initBtn : {} + }; + /** + * 初始化方法 + */ + window[nameSpace].init = function(el, options) { + var identification = Math.floor(Math.round() * 10000000000) + .toString(); + window[nameSpace].initBtn[identification] = new Builder(el, + options, _self, identification); + } + } +}) + ( + window, + function() { + /** + * js,css文件加载方法 + */ + var dynamicLoading = { + css : function(path, name, callBk) { + if (!path || path.length === 0) { + throw new Error('argument "path" is required !'); + } + var head = document.getElementsByTagName('head')[0]; + var link = document.createElement('link'); + link.href = path; + link.rel = 'stylesheet'; + link.type = 'text/css'; + link.setAttribute('data-name', name); + link.onload = function() { + callBk(); + } + head.appendChild(link); + }, + insertCss : function(innerTexts, name) { + var head = document.getElementsByTagName('head')[0]; + var style = document.createElement('style'); + style.type = 'text/css'; + style.setAttribute('data-name', name); + try { + style.appendChild(document + .createTextNode(innerTexts)); + } catch (ex) { + style.styleSheet.cssText = innerTexts;// 针对IE + } + head.appendChild(style); + }, + checkCss : function(name) { + var styleList = document + .getElementsByTagName('style'); + for (var i = 0; i < styleList.length; i++) { + if (styleList[i].getAttribute('data-name') === name) + return true; + } + return false; + }, + js : function(path, callBk) { + if (!path || path.length === 0) { + throw new Error('argument "path" is required !'); + } + var head = document.getElementsByTagName('head')[0]; + var script = document.createElement('script'); + script.src = path; + script.type = 'text/javascript'; + script.onload = function() { + callBk(); + } + head.appendChild(script); + }, + checkJs : function(name) { + var scriptList = document + .getElementsByTagName('script'); + for (var i = 0; i < scriptList.length; i++) { + if (scriptList[i].getAttribute('data-name') === name) + return true; + } + return false; + }, + } + /** + * 浏览器 + */ + function myBrowser() { + var userAgent = navigator.userAgent; // 取得浏览器的userAgent字符串 + var isOpera = userAgent.indexOf("Opera") > -1; + if (isOpera) { // 判断是否Opera浏览器 + return "Opera" + } + ; + if (userAgent.indexOf("Firefox") > -1) { // 判断是否Firefox浏览器 + return "FF"; + } + ; + if (userAgent.indexOf("Chrome") > -1) { + return "Chrome"; + } + ; + if (userAgent.indexOf("Safari") > -1) { // 判断是否Safari浏览器 + return "Safari"; + } + ; + if (userAgent.indexOf("compatible") > -1 + && userAgent.indexOf("MSIE") > -1 && !isOpera) { // 判断是否IE浏览器 + return "IE"; + } + ; + } + /** + * 定义标签打印按钮的构造函数 + * + * @param {*} + * options + * @param {*} + * _self + */ + function labelPrintingBtn(el, options, _self, + identification) { + var self = this; + self.window_self = _self; + self.el = el; + self.identification = identification; + // 解析传进来的数据 + self.initParams(options); + // 处理挂载 + self.initBtn(el); + // 销毁自己 + self.beforeDestroy = function() { + self = null; + } + } + /** + * 构造函数的原型方法 + */ + labelPrintingBtn.prototype = { + initParams : function(options) { + this.place = options.place; + this.rowData = options.rowData; + this.data = options.data; + }, + initBtn : function(el) { + /** + * 挂载dom初始化处理 + */ + var innerTexts = '.labelPrintingBtnHandler {' + + 'background-color: rgba(0,0,0,0);' + + 'font-family: "Ping Fang SC", "Microsoft YaHei", Arial, Helvetica, sans-serif, "SimSun";' + + 'cursor: pointer;' + + 'white-space : nowrap;' + + 'border: 0;' + + 'overflow: hidden;' + + 'text-overflow: ellipsis;' + + '}' + + '.labelPrintingBtnBox { box-sizing: border-box; cursor: pointer; outline: none; font-family: inherit; white-space: nowrap;display: inline-block; margin-top: 5px; vertical-align: middle; margin-right: 5px;' + + ' background-color: #fff; border: 1px solid #d4d4d4; color: #666;font-size: 14px; line-height: 28px; border-radius: 15px; height: 30px;}' + + '.labelPrintingBtnBox:hover{ border-color: #1f85ec; }' + + '.labelPrintingBtnRow{color: #1f85ec;}' + + '.labelPrintingBtnRow:hover{color : #479bf3}' + + '.labelPrintingBtnLi{color : #333}' + + '.labelPrintingBtnLi:hover{color : #fff}'; + if (!dynamicLoading.checkCss('labelPrintingBtn')) { + dynamicLoading.insertCss(innerTexts, + 'labelPrintingBtn'); + } + // 挂载dom + this.appendDom(el); + }, + appendDom : function(el) { + var self = this; + var labelPrint = document.createElement('div'), labelPrintToolbar, labelPrintIcon; + // 对代码片段进行配置 + el.appendChild(labelPrint); + // 根据不同位置渲染按钮 + switch (this.place) { + case 'toolbar': + labelPrint.parentNode.setAttribute('class', + 'labelPrintingBtnBox'); + labelPrint.style.padding = '0 14px'; + // 加入icon + labelPrintIcon = document.createElement('i'); + labelPrintIcon.setAttribute('class', + 'CAP cap-icon-dayin'); + labelPrintIcon.style.color = '#C3AF1C'; + labelPrint.appendChild(labelPrintIcon); + // 加入name信息 + labelPrintToolbar = document + .createElement('span'); + labelPrintToolbar.innerHTML = this.data + && this.data.name ? this.data.name : ''; + labelPrintToolbar.style.paddingLeft = '3px'; + labelPrint.appendChild(labelPrintToolbar); + break; + case 'li': + labelPrint.innerHTML = this.data + && this.data.name ? this.data.name : ''; + labelPrint + .setAttribute('class', + 'labelPrintingBtnLi labelPrintingBtnHandler') + break; + case 'row': + labelPrint.innerHTML = this.data + && this.data.name ? this.data.name : ''; + labelPrint + .setAttribute('class', + 'labelPrintingBtnRow labelPrintingBtnHandler') + break; + default: + } + labelPrint.onclick = function() { + switch (self.place) { + case 'toolbar': + // 点击执行对应的操作 + self.implementClick(); + break; + case 'li': + case 'row': + // 点击执行对应的操作 + self.implementClick(self.rowData); + break; + default: + } + + } + // 阻止数据污染 + labelPrint.parentNode.onclick = function(e) { + e.stopPropagation(); + } + }, + // 执行点击事件 + implementClick : function(rowData) { + var self = this; + var datas; + if (!rowData && window.extendApi + && window.extendApi.getChooseId) { + datas = window.extendApi.getChooseId(); + } else { + datas = rowData.id; + } + // 获取模版id + this.handlerLogic(datas); + }, + // 点击逻辑执行 + handlerLogic : function(rowData) { + this.generateBatchCode(); + this.openSaoMiaoYi(); + }, + + generateBatchCode: function() { + var saoMiaoYiApiBaseUrl = "http://localhost:8080"; + + var res = this.syncRequest("GET", saoMiaoYiApiBaseUrl + "/jControls/getBatchNumber"); + + if (res && res.data && res.data.batchNumber) { + window.localStorage.setItem('saomiaoyi', res.data.batchNumber); + return res.data.batchNumber; + } + return null; + }, + + openSaoMiaoYi: function() { + var saoMiaoYiApiBaseUrl = "http://localhost:8080"; + this.syncRequest("GET", saoMiaoYiApiBaseUrl + "/jControls/getStart"); + }, + syncRequest: function(method, url, body, headers) { + var xhr = new XMLHttpRequest(); + xhr.open(method, url, false); // false = 阻塞 + if (headers) { + for (var key in headers) { + xhr.setRequestHeader(key, headers[key]); + } + } + xhr.send(body || null); + + if (xhr.status === 200) { + return JSON.parse(xhr.responseText); + } else { + console.error("请求失败:", xhr.status, xhr.responseText); + return null; + } + } + }; + /** + * 返回值 + */ + return labelPrintingBtn; + }); \ No newline at end of file diff --git a/v5/apps-customize/src/test/SheBaoFenZhangTest.java b/v5/apps-customize/src/test/SheBaoFenZhangTest.java new file mode 100644 index 0000000..22c43cf --- /dev/null +++ b/v5/apps-customize/src/test/SheBaoFenZhangTest.java @@ -0,0 +1,7 @@ +import com.seeyon.apps.jync_fz.node.SheBaoFenZhangNode; + +public class SheBaoFenZhangTest { + public static void main(String[] args) { + SheBaoFenZhangNode sheBaoFenZhangNode = new SheBaoFenZhangNode(); + } +}