From 4737c71a78c696c9150ef522fa0266739f7cc981 Mon Sep 17 00:00:00 2001 From: yem_rabbit_lhb Date: Tue, 14 Jan 2025 17:59:02 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=20yem-base/yem-base-common/s?= =?UTF-8?q?rc/main/java/yem/base/common/utils/TwoOpenCommFuncUtil.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 变更文件位置及类名 新工具类:AccessoryToolsUtil --- .../common/utils/TwoOpenCommFuncUtil.java | 295 ------------------ 1 file changed, 295 deletions(-) delete mode 100644 yem-base/yem-base-common/src/main/java/yem/base/common/utils/TwoOpenCommFuncUtil.java diff --git a/yem-base/yem-base-common/src/main/java/yem/base/common/utils/TwoOpenCommFuncUtil.java b/yem-base/yem-base-common/src/main/java/yem/base/common/utils/TwoOpenCommFuncUtil.java deleted file mode 100644 index 6d36813..0000000 --- a/yem-base/yem-base-common/src/main/java/yem/base/common/utils/TwoOpenCommFuncUtil.java +++ /dev/null @@ -1,295 +0,0 @@ -package yem.base.common.utils; - -/** - * @author lipan - * @date 2024/1/18 9:49 - * @className TwoOpenCommFuncUtil - * @description - */ - -import com.alibaba.fastjson.JSONObject; -import kd.bos.bill.AbstractBillPlugIn; -import kd.bos.dataentity.entity.DynamicObject; -import kd.bos.dataentity.entity.DynamicObjectCollection; -import kd.bos.dataentity.entity.OrmLocaleValue; -import kd.bos.entity.datamodel.IDataModel; -import kd.bos.form.control.AttachmentPanel; -import kd.bos.form.field.LargeTextEdit; -import kd.bos.ksql.util.StringUtil; - -import java.text.SimpleDateFormat; -import java.util.*; -import java.util.stream.Collectors; - -/** - * @author xwudd - * @Description 二开单据共用方法 - */ -public class TwoOpenCommFuncUtil { - - /** - * @param model - * @Description 二开单据商品分录第一行商品带出品名 - */ - public static void setProductName(IDataModel model) { - DynamicObjectCollection materialentrys = model.getEntryEntity("yem_materialentry"); - if (materialentrys.size() == 0) { - model.setValue("yem_productname", null); - } - for (DynamicObject materialentry : materialentrys) { - DynamicObject material = materialentry.getDynamicObject("yem_material"); - if (material != null) { - model.setValue("yem_productname", material.getString("simplepinyin")); - break; - } else { - model.setValue("yem_productname", null); - } - } - } - - - /** - * @param form - * @param largeText - * @Description 增加/更新附件 - */ - public static void addAttachmentContext(AbstractBillPlugIn form, String largeText, List attachmentpanelKey) { - - for (String s : attachmentpanelKey) { - - attachmentForm(form, largeText, "yem_attachmentdetail", s); - } - } - - /** - * @param form - * @param largeText - * @Description 删除附件 - */ - public static void removeAttachmentContext(AbstractBillPlugIn form, String largeText, List attachmentpanelKey) { - Set urlSet = new HashSet<>(); - for (String s : attachmentpanelKey) { - AttachmentPanel attachmentpanel = form.getView().getControl(s); - List> attachmentDatas = attachmentpanel.getAttachmentData(); - for (Map attachmentData : attachmentDatas) { - String uid = (String) attachmentData.get("uid"); - urlSet.add(uid); - } - } - //附件分录 - DynamicObjectCollection attachmentDetail = form.getView().getModel() - .getDataEntity(true). - getDynamicObjectCollection("yem_attachmentdetail"); - // 找出需要删除的记录(在urld中有但在urls中没有的记录) - List toDelete = new ArrayList<>(); - for (int i = 0; i < attachmentDetail.size(); i++) { - DynamicObject attachment = attachmentDetail.get(i); - String url = attachment.getString("yem_uid"); - if (!urlSet.contains(url)) { - toDelete.add(i); - } - } - if (!toDelete.isEmpty()) { - int[] array = toDelete.stream().mapToInt(Integer::intValue).toArray(); - form.getView().getModel().deleteEntryRows("yem_attachmentdetail", array); - } - } - - /** - * @param form - * @param largeText - * @param entityName - * @Description 附件表格赋值 - */ - public static void attachmentForm(AbstractBillPlugIn form, String largeText, String entityName, String attachmentpanelKey) { - Map> attachmentMap = buildAttachmentMap(form, attachmentpanelKey); - DynamicObjectCollection attachmentDetail = form.getView().getModel().getDataEntity(true).getDynamicObjectCollection(entityName); - String billno = (String) form.getView().getModel().getValue("billno"); - - // 获取现有的 UID 列表 - Set existingUids = attachmentDetail.stream() - .map(detail -> detail.getString("yem_uid")) - .collect(Collectors.toSet()); - - // 处理每个附件 - attachmentMap.forEach((uid, value) -> { - if (existingUids.contains(uid)) { - updateExistingAttachment(form, attachmentDetail, uid, value, billno, attachmentpanelKey); - } else { - createNewAttachment(form, entityName, uid, value, billno, attachmentpanelKey); - } - }); - } - - /** - * 构建附件map - * - * @param form - * @param attachmentpanelKey - * @return - */ - private static Map> buildAttachmentMap(AbstractBillPlugIn form, String attachmentpanelKey) { - Map> attachmentMap = new HashMap<>(); - AttachmentPanel attachmentPanel = form.getView().getControl(attachmentpanelKey); - List> attachmentDatas = attachmentPanel.getAttachmentData(); - - for (Map attachmentData : attachmentDatas) { - String uid = (String) attachmentData.get("uid"); - String name = (String) attachmentData.get("name"); - String url = (String) attachmentData.get("url"); - Long createTime = (Long) attachmentData.get("createdate"); - - // 格式化时间 - String formattedTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(createTime)); - - // 获取创建人 - @SuppressWarnings("unchecked") - Map creator = (Map) attachmentData.get("creator"); - String creatorName = creator != null ? (String) creator.get("zh_CN") : null; - - // 存储数据 - Map dataMap = new HashMap<>(); - dataMap.put("name", name); - dataMap.put("url", url); - dataMap.put("createTime", formattedTime); - dataMap.put("creator", creatorName); - attachmentMap.put(uid, dataMap); - } - return attachmentMap; - } - - /** - * 更新附件行 - * - * @param form - * @param attachmentDetail - * @param uid - * @param data - * @param billno - * @param attachmentpanelKey - */ - private static void updateExistingAttachment(AbstractBillPlugIn form, DynamicObjectCollection attachmentDetail, - String uid, Map data, String billno, - String attachmentpanelKey) { - for (DynamicObject attachment : attachmentDetail) { - if (uid.equals(attachment.getString("yem_uid"))) { - int rowIndex = attachmentDetail.indexOf(attachment); - setAttachmentValues(form, rowIndex, uid, data, billno, attachmentpanelKey); - break; - } - } - } - - /** - * 增加新附件行 - * - * @param form - * @param entityName - * @param uid - * @param data - * @param billno - * @param attachmentpanelKey - */ - private static void createNewAttachment(AbstractBillPlugIn form, String entityName, String uid, - Map data, String billno, - String attachmentpanelKey) { - int newRow = form.getView().getModel().createNewEntryRow(entityName); - setAttachmentValues(form, newRow, uid, data, billno, attachmentpanelKey); - } - - /** - * 附件分录赋值 - * @param form - * @param row - * @param uid - * @param data - * @param billno - * @param attachmentpanelKey - */ - private static void setAttachmentValues(AbstractBillPlugIn form, int row, String uid, - Map data, String billno, - String attachmentpanelKey) { - form.getView().getModel().setValue("yem_attachmentname", data.get("name"), row); - form.getView().getModel().setValue("yem_url", data.get("url"), row); - form.getView().getModel().setValue("yem_panel", attachmentpanelKey, row); - form.getView().getModel().setValue("yem_billno", billno, row); - form.getView().getModel().setValue("yem_uid", uid, row); - form.getView().getModel().setValue("yem_uploaddate", data.get("createTime"), row); - form.getView().getModel().setValue("yem_creator", data.get("creator"), row); - } - - /** - * @param form - * @param largeText - * @param entityName - * @Description 附件表格RPA比对结果赋值 - */ - public static void attachmentFormRPA(AbstractBillPlugIn form, String largeText, String entityName, String tarFilesName, int type) { - //获取存储内容 - LargeTextEdit largeTextEdit = form.getView().getControl(largeText); - - //add by zhangh 20230508 其他单据为添加rpa对接字段 - if (largeTextEdit != null) { - String tagFieldKey = largeTextEdit.getTagFieldKey(); - String context = (String) form.getView().getModel().getValue(tagFieldKey); - JSONObject json = null; - if (!StringUtil.isEmpty(context)) { - json = JSONObject.parseObject(context); - } - // 获取附件表格的值 - DynamicObjectCollection entry = form.getView().getModel().getEntryEntity("yem_attachmentdetail"); - if (json == null || entry == null || entry.size() == 0) return; - Set keySets = json.keySet(); - // 比对结果赋值 - for (int i = 0; i < entry.size(); i++) { - String name = entry.get(i).getString("yem_attachmentname"); - if (keySets.contains(name)) { -// if (type == 1)form.getView().getModel().setValue(tarFilesName, (String)json.get(name),i); -// if (type == 2)form.getView().getModel().setValue(tarFilesName, (Boolean)json.get(name),i); - // 3.1 金亮修改(之前保错) - Object objName = json.get(name); - if (objName instanceof Long) { - if (type == 1) form.getView().getModel().setValue(tarFilesName, (Long) json.get(name), i); - } else if (objName instanceof String) { - if (type == 1) form.getView().getModel().setValue(tarFilesName, (String) json.get(name), i); - } else if (objName instanceof Boolean) { - if (type == 2) form.getView().getModel().setValue(tarFilesName, (Boolean) json.get(name), i); - } - } - } - } - } - - /** - * @param form - * @param largeText - * @param row - * @Description设置附件类型 - */ - public static void setAttachmentType(AbstractBillPlugIn form, String largeText, int row) { - LargeTextEdit largeTextEdit = form.getView().getControl(largeText); - String tagFieldKey = largeTextEdit.getTagFieldKey(); - String context = (String) form.getView().getModel().getValue(tagFieldKey); - JSONObject json = null; - if (!StringUtil.isEmpty(context)) { - json = JSONObject.parseObject(context); - } - if (json == null) { - json = new JSONObject(); - } - String key = ""; - OrmLocaleValue keyLocal = (OrmLocaleValue) form.getView().getModel().getValue("yem_attachmentname", row); - if (keyLocal != null) { - key = keyLocal.getLocaleValue(); - } - DynamicObject value = (DynamicObject) form.getView().getModel().getValue("yem_attachmenttype", row); - if (value != null) { - json.put(key, value.getPkValue()); - } else { - json.put(key, ""); - } - form.getView().getModel().setValue(tagFieldKey, json.toJSONString()); - } - - -}