Merge pull request 'yem_rabbit_lhb' (#22) from yem_rabbit_lhb into main
Reviewed-on: #22
This commit is contained in:
commit
c9d8a507f1
2
.gitignore
vendored
2
.gitignore
vendored
@ -19,8 +19,10 @@
|
|||||||
*.zip
|
*.zip
|
||||||
*.tar.gz
|
*.tar.gz
|
||||||
*.rar
|
*.rar
|
||||||
|
*.MF
|
||||||
|
|
||||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||||
hs_err_pid*
|
hs_err_pid*
|
||||||
replay_pid*
|
replay_pid*
|
||||||
|
|
||||||
|
|
||||||
|
Binary file not shown.
@ -0,0 +1,356 @@
|
|||||||
|
package yem.base.common.module.attach.form;
|
||||||
|
|
||||||
|
import kd.bos.bill.AbstractBillPlugIn;
|
||||||
|
import kd.bos.bill.OperationStatus;
|
||||||
|
import kd.bos.dataentity.OperateOption;
|
||||||
|
import kd.bos.dataentity.entity.DynamicObject;
|
||||||
|
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
||||||
|
import kd.bos.dataentity.utils.StringUtils;
|
||||||
|
import kd.bos.entity.EntityMetadataCache;
|
||||||
|
import kd.bos.entity.MainEntityType;
|
||||||
|
import kd.bos.entity.datamodel.IDataModel;
|
||||||
|
import kd.bos.form.FormShowParameter;
|
||||||
|
import kd.bos.form.IFormView;
|
||||||
|
import kd.bos.form.control.AttachmentPanel;
|
||||||
|
import kd.bos.form.control.events.BeforeAttachmentRemoveEvent;
|
||||||
|
import kd.bos.form.control.events.BeforeAttachmentRemoveListener;
|
||||||
|
import kd.bos.form.control.events.UploadEvent;
|
||||||
|
import kd.bos.form.control.events.UploadListener;
|
||||||
|
import kd.bos.form.events.AfterDoOperationEventArgs;
|
||||||
|
import kd.bos.metadata.dao.MetaCategory;
|
||||||
|
import kd.bos.metadata.dao.MetadataDao;
|
||||||
|
import kd.bos.metadata.form.ControlAp;
|
||||||
|
import kd.bos.metadata.form.FormMetadata;
|
||||||
|
import kd.bos.metadata.form.control.AttachmentPanelAp;
|
||||||
|
import kd.bos.orm.query.QCP;
|
||||||
|
import kd.bos.orm.query.QFilter;
|
||||||
|
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
||||||
|
import kd.bos.servicehelper.operation.OperationServiceHelper;
|
||||||
|
import kd.bos.servicehelper.user.UserServiceHelper;
|
||||||
|
import yem.base.common.utils.DynamicObjectUtil;
|
||||||
|
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description 附件表单功能
|
||||||
|
* @Author: LiuHB
|
||||||
|
* @CreateTime: 2025-02-17 10:42
|
||||||
|
*/
|
||||||
|
public class AccessoryToolsBillPlugin extends AbstractBillPlugIn implements UploadListener ,BeforeAttachmentRemoveListener{
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 注册监听器,定义了在注册监听器时的操作。
|
||||||
|
* @param e 事件对象,表示要注册监听的事件。
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void registerListener(EventObject e) {
|
||||||
|
super.registerListener(e);
|
||||||
|
AttachmentPanel attachmentPanel = this.getView().getControl("attachmentpanel");
|
||||||
|
attachmentPanel.addUploadListener(this);
|
||||||
|
attachmentPanel.addBeforeRemoveListener(this);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 根据操作结果控制界面
|
||||||
|
* @function 1.点击保存或提交后为附件分录的【单据id】字段赋值
|
||||||
|
* @purposes 用户点击按钮、菜单,执行完绑定的操作后,不论成功与否,均会触发此事件
|
||||||
|
* @param e
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void afterDoOperation(AfterDoOperationEventArgs e) {
|
||||||
|
super.afterDoOperation(e);
|
||||||
|
IFormView view = this.getView();
|
||||||
|
IDataModel model = view.getModel();
|
||||||
|
String operateKey = e.getOperateKey();
|
||||||
|
switch (operateKey) {
|
||||||
|
case "save":
|
||||||
|
case "submit":
|
||||||
|
String formName = this.getView().getModel().getDataEntity(true).getDynamicObjectType().getName();
|
||||||
|
Set<String> attachmentkey = getAttachControl(formName).keySet();
|
||||||
|
//增加/更新附件
|
||||||
|
attachmentForm("yem_attachmentinfo_e", attachmentkey);
|
||||||
|
DynamicObjectCollection attachmentinfo_e = this.getView().getModel().getDataEntity(true).getDynamicObjectCollection("yem_attachmentinfo_e");
|
||||||
|
for (int i = 0; i < attachmentinfo_e.size(); i++) {
|
||||||
|
model.setValue("yem_billid", model.getValue("id"), i);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 用户在前端附件面板,上传文件后,系统自动调用
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void afterUpload(UploadEvent evt) {
|
||||||
|
UploadListener.super.afterUpload(evt);
|
||||||
|
String formName = this.getView().getModel().getDataEntity(true).getDynamicObjectType().getName();
|
||||||
|
Set<String> attachmentkey = getAttachControl(formName).keySet();
|
||||||
|
//增加/更新附件
|
||||||
|
attachmentForm("yem_attachmentinfo_e", attachmentkey);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @Description: 用户在前端附件面板,删除文件前,系统自动调用
|
||||||
|
* @function 校验:当前登陆人不能删除其他人上传的附件
|
||||||
|
* @param e
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void beforeAttachmentRemove(BeforeAttachmentRemoveEvent e) {
|
||||||
|
FormShowParameter showParameter = this.getView().getFormShowParameter();
|
||||||
|
String status = showParameter.getStatus().toString();
|
||||||
|
if (!status.equals("ADDNEW")) {
|
||||||
|
long userId = UserServiceHelper.getCurrentUserId();
|
||||||
|
DynamicObject bos_user = BusinessDataServiceHelper.loadSingleFromCache(userId, "bos_user");
|
||||||
|
Map<String, Object> map = e.getAttachemnt();
|
||||||
|
AttachmentPanel attachmentPanel = (AttachmentPanel) e.getSource();
|
||||||
|
String uid = (String) map.get("uid");
|
||||||
|
List<Map<String, Object>> attachmentData = attachmentPanel.getAttachmentData();
|
||||||
|
for (Map<String, Object> data : attachmentData) {
|
||||||
|
String uidAttachment = (String) data.get("uid");
|
||||||
|
if (!StringUtils.isEmpty(uidAttachment)) {
|
||||||
|
if (uidAttachment.equals(uid)) {
|
||||||
|
String creator = data.get("creator").toString();
|
||||||
|
if (!creator.contains(bos_user.getString("name"))) {
|
||||||
|
e.setMsg("不能删除别人上传的附件!!!");
|
||||||
|
e.setCancel(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 用户在前端附件面板,删除文件后,系统自动调用
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void afterRemove(UploadEvent evt) {
|
||||||
|
UploadListener.super.afterRemove(evt);
|
||||||
|
String formName = this.getView().getModel().getDataEntity(true).getDynamicObjectType().getName();
|
||||||
|
Map<String, String> attachControl = getAttachControl(formName);
|
||||||
|
Set<String> attachControlkey = attachControl.keySet();
|
||||||
|
removeAttachmentContext(attachControlkey,formName);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description 附件表格赋值
|
||||||
|
* @function 1.根据传入的附件面板标识,获取到各个附件面板的数据,调用buildAttachmentMap()方法,返回附件数据集合
|
||||||
|
* key: 附件uid value:附件信息
|
||||||
|
* 2.将现有的附件uid存入set
|
||||||
|
* 3.判断调整后的附件面板的附件uid和附件分录的是否包含
|
||||||
|
* 包含:根据获取到的附件信息更新分录数据
|
||||||
|
* 不包含:新增附件分录数据
|
||||||
|
* @param yemAttachmentdetail 附件分录标识
|
||||||
|
* @param attachmentkey 附件面板标识集合
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
|
||||||
|
private void attachmentForm(String yemAttachmentdetail, Set<String> attachmentkey) {
|
||||||
|
Map<String, Map<String, Object>> attachmentMap = buildAttachmentMap(attachmentkey);
|
||||||
|
DynamicObjectCollection attachmentDetail = this.getView().getModel().getDataEntity(true).getDynamicObjectCollection(yemAttachmentdetail);
|
||||||
|
// 获取现有的 UID 列表
|
||||||
|
Set<String> existingUids = attachmentDetail.stream()
|
||||||
|
.map(detail -> detail.getString("yem_attachedid"))
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
|
||||||
|
// 处理每个附件
|
||||||
|
attachmentMap.forEach((uid, value) -> {
|
||||||
|
if (existingUids.contains(uid)) {
|
||||||
|
//更新
|
||||||
|
updateExistingAttachment( attachmentDetail, uid, value,(String) value.get("attachmentpanelKey"));
|
||||||
|
} else {
|
||||||
|
//新增
|
||||||
|
createNewAttachment( yemAttachmentdetail, uid, value, (String) value.get("attachmentpanelKey"));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description 更新附件行
|
||||||
|
* @param attachmentDetail 附件分录
|
||||||
|
* @param uid 附件uid
|
||||||
|
* @param data 附件信息
|
||||||
|
* @param attachmentpanelKey 附件面板标识
|
||||||
|
*/
|
||||||
|
private void updateExistingAttachment(DynamicObjectCollection attachmentDetail,
|
||||||
|
String uid, Map<String, Object> data,
|
||||||
|
String attachmentpanelKey) {
|
||||||
|
for (DynamicObject attachment : attachmentDetail) {
|
||||||
|
if (uid.equals(attachment.getString("yem_attachedid"))) {
|
||||||
|
int rowIndex = attachmentDetail.indexOf(attachment);
|
||||||
|
setAttachmentValues(this, rowIndex, uid, data, attachmentpanelKey);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description 增加新附件行
|
||||||
|
* @param entityName 附件分录标识
|
||||||
|
* @param uid 附件uid
|
||||||
|
* @param data 附件信息
|
||||||
|
* @param attachmentpanelKey 附件面板标识
|
||||||
|
*/
|
||||||
|
private void createNewAttachment(String entityName, String uid, Map<String, Object> data,
|
||||||
|
String attachmentpanelKey) {
|
||||||
|
int newRow = this.getView().getModel().createNewEntryRow(entityName);
|
||||||
|
setAttachmentValues(this,newRow, uid, data, attachmentpanelKey);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @Description 附件分录赋值
|
||||||
|
*/
|
||||||
|
private static void setAttachmentValues(AbstractBillPlugIn form, int row, String uid,
|
||||||
|
Map<String, Object> data,
|
||||||
|
String attachmentpanelKey) {
|
||||||
|
//单据标识
|
||||||
|
String billName = form.getView().getModel().getDataEntity(true).getDataEntityType().getName();
|
||||||
|
form.getView().getModel().setValue("yem_attachmentname", data.get("name"), row);//附件名称
|
||||||
|
form.getView().getModel().setValue("yem_atturl", data.get("url"), row);//url
|
||||||
|
form.getView().getModel().setValue("yem_panel", attachmentpanelKey, row);//附件面板
|
||||||
|
form.getView().getModel().setValue("yem_billno",form.getView().getModel().getValue("billno"), row);//单据编号
|
||||||
|
form.getView().getModel().setValue("yem_docid",billName, row);//单据标识
|
||||||
|
form.getView().getModel().setValue("yem_billid",form.getView().getModel().getValue("id"), row);//单据id
|
||||||
|
form.getView().getModel().setValue("yem_attachedid", uid, row);//uid
|
||||||
|
form.getView().getModel().setValue("yem_uploaddate", data.get("createTime"), row);//上传时间
|
||||||
|
Long currentUserId = UserServiceHelper.getCurrentUserId();
|
||||||
|
form.getView().getModel().setValue("yem_attacheduser", currentUserId, row);//上传人
|
||||||
|
QFilter qFilter = new QFilter("yem_bill.number", QCP.equals, billName);
|
||||||
|
qFilter.and("yem_isdefault",QCP.equals,true);
|
||||||
|
DynamicObject attachmenttype = BusinessDataServiceHelper.loadSingle("yem_bd_attachmenttype", qFilter.toArray());
|
||||||
|
form.getView().getModel().setValue("yem_attachmenttype", attachmenttype, row);//上传时间
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description 构建附件map
|
||||||
|
* @function 功能
|
||||||
|
* @purposes 准备附件分录需要的数据
|
||||||
|
* @param attachmentkey
|
||||||
|
* @return java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.Object>>
|
||||||
|
* key:附件uid value:附件信息
|
||||||
|
*/
|
||||||
|
|
||||||
|
private Map<String, Map<String, Object>> buildAttachmentMap(Set<String> attachmentkey) {
|
||||||
|
Map<String, Map<String, Object>> attachmentMap = new HashMap<>();
|
||||||
|
for (String sattachmentinfo : attachmentkey) {
|
||||||
|
AttachmentPanel attachmentPanel = this.getView().getControl(sattachmentinfo);
|
||||||
|
List<Map<String, Object>> attachmentDatas = attachmentPanel.getAttachmentData();
|
||||||
|
|
||||||
|
for (Map<String, Object> 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<String, Object> creator = (Map<String, Object>) attachmentData.get("creator");
|
||||||
|
String creatorName = creator != null ? (String) creator.get("zh_CN") : null;
|
||||||
|
|
||||||
|
// 存储数据
|
||||||
|
Map<String, Object> dataMap = new HashMap<>();
|
||||||
|
dataMap.put("name", name);
|
||||||
|
dataMap.put("url", url);
|
||||||
|
dataMap.put("createTime", formattedTime);
|
||||||
|
dataMap.put("creator", creatorName);
|
||||||
|
dataMap.put("attachmentpanelKey",sattachmentinfo);
|
||||||
|
attachmentMap.put(uid, dataMap);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return attachmentMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 删除附件
|
||||||
|
* @function 1.获取当前页面所有附件面板的附件id
|
||||||
|
* 2.遍历附件分录,判断分录id是否包含在附件面板id集合中,包含则记录行号,遍历完成删行处理
|
||||||
|
* @purposes 用途
|
||||||
|
* @param attachmentpanelKey 附件面板标识集合
|
||||||
|
* @param formName 单据标识
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
|
||||||
|
private void removeAttachmentContext(Set<String> attachmentpanelKey, String formName) {
|
||||||
|
|
||||||
|
Set<String> urlSet = new HashSet<>();
|
||||||
|
for (String attachmentpanel : attachmentpanelKey) {
|
||||||
|
AttachmentPanel attachment = this.getView().getControl(attachmentpanel);
|
||||||
|
List<Map<String, Object>> attachmentDatas = attachment.getAttachmentData();
|
||||||
|
for (Map<String, Object> attachmentData : attachmentDatas) {
|
||||||
|
urlSet.add((String) attachmentData.get("uid"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//附件分录
|
||||||
|
DynamicObjectCollection attachmentDetail = this.getView().getModel()
|
||||||
|
.getDataEntity(true).
|
||||||
|
getDynamicObjectCollection("yem_attachmentinfo_e");
|
||||||
|
// 找出需要删除的记录(在urld中有但在urls中没有的记录)
|
||||||
|
List<Integer> toDelete = new ArrayList<>();
|
||||||
|
for (int i = 0; i < attachmentDetail.size(); i++) {
|
||||||
|
DynamicObject attachment = attachmentDetail.get(i);
|
||||||
|
if (!urlSet.contains(attachment.getString("yem_attachedid"))) {
|
||||||
|
toDelete.add(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!toDelete.isEmpty()) {
|
||||||
|
int[] array = toDelete.stream().mapToInt(Integer::intValue).toArray();
|
||||||
|
this.getView().getModel().deleteEntryRows("yem_attachmentinfo_e", array);
|
||||||
|
}
|
||||||
|
FormShowParameter showParameter = this.getView().getFormShowParameter();
|
||||||
|
if (!showParameter.getStatus().equals(OperationStatus.ADDNEW)) {
|
||||||
|
OperationServiceHelper.executeOperate("save", formName, new DynamicObject[]{this.getView().getModel().getDataEntity(true)}, OperateOption.create());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 获取源单实体所有附件面板的key\name
|
||||||
|
* @param formName 源单标识
|
||||||
|
* @return java.util.Map<java.lang.String,java.lang.String>
|
||||||
|
* key:附件面板标识
|
||||||
|
* value:附件面板名称
|
||||||
|
*/
|
||||||
|
|
||||||
|
private Map<String, String> getAttachControl(String formName) {
|
||||||
|
MainEntityType entityType = EntityMetadataCache.getDataEntityType(formName);
|
||||||
|
FormMetadata taskMeta = (FormMetadata) MetadataDao.readRuntimeMeta(MetadataDao.getIdByNumber(
|
||||||
|
entityType.getName(), MetaCategory.Form), MetaCategory.Form);
|
||||||
|
List<ControlAp<?>> items = taskMeta.getItems();
|
||||||
|
// 附件面板标识集合。
|
||||||
|
Map<String, String> attachmentPanelAp = new HashMap<>();
|
||||||
|
items.forEach(item -> {
|
||||||
|
if (item instanceof AttachmentPanelAp) {
|
||||||
|
AttachmentPanelAp attachmentPanel = (AttachmentPanelAp) item;
|
||||||
|
attachmentPanelAp.put(attachmentPanel.getKey(), String.valueOf(attachmentPanel.getName()));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return attachmentPanelAp;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,187 @@
|
|||||||
|
package yem.base.common.module.attach.util;
|
||||||
|
|
||||||
|
|
||||||
|
import kd.bos.bill.AbstractBillPlugIn;
|
||||||
|
import kd.bos.dataentity.entity.DynamicObject;
|
||||||
|
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
||||||
|
import kd.bos.form.control.AttachmentPanel;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
/**
|
||||||
|
* 附件工具类
|
||||||
|
* @BelongsProject: yem-cosmic
|
||||||
|
* @BelongsPackage: yem.base.common.utils
|
||||||
|
* @ClassName AccessoryToolsUtil
|
||||||
|
* @Author: LiuHB
|
||||||
|
* @CreateTime: 2025-01-14 17:15
|
||||||
|
*/
|
||||||
|
public class AccessoryToolsUtil {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param form
|
||||||
|
* @param attachmentpanelKey
|
||||||
|
* @Description 增加/更新附件
|
||||||
|
*/
|
||||||
|
public static void addAttachmentContext(AbstractBillPlugIn form, List<String> attachmentpanelKey) {
|
||||||
|
|
||||||
|
for (String s : attachmentpanelKey) {
|
||||||
|
|
||||||
|
attachmentForm(form,"yem_attachmentdetail", s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param form
|
||||||
|
* @param attachmentpanelKey
|
||||||
|
* @Description 删除附件
|
||||||
|
*/
|
||||||
|
public static void removeAttachmentContext(AbstractBillPlugIn form, List<String> attachmentpanelKey) {
|
||||||
|
Set<String> urlSet = new HashSet<>();
|
||||||
|
for (String s : attachmentpanelKey) {
|
||||||
|
AttachmentPanel attachmentpanel = form.getView().getControl(s);
|
||||||
|
List<Map<String, Object>> attachmentDatas = attachmentpanel.getAttachmentData();
|
||||||
|
for (Map<String, Object> attachmentData : attachmentDatas) {
|
||||||
|
String uid = (String) attachmentData.get("uid");
|
||||||
|
urlSet.add(uid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//附件分录
|
||||||
|
DynamicObjectCollection attachmentDetail = form.getView().getModel()
|
||||||
|
.getDataEntity(true).
|
||||||
|
getDynamicObjectCollection("yem_attachmentdetail");
|
||||||
|
// 找出需要删除的记录(在urld中有但在urls中没有的记录)
|
||||||
|
List<Integer> 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 entityName
|
||||||
|
* @Description 附件表格赋值
|
||||||
|
*/
|
||||||
|
public static void attachmentForm(AbstractBillPlugIn form, String entityName, String attachmentpanelKey) {
|
||||||
|
Map<String, Map<String, Object>> attachmentMap = buildAttachmentMap(form, attachmentpanelKey);
|
||||||
|
DynamicObjectCollection attachmentDetail = form.getView().getModel().getDataEntity(true).getDynamicObjectCollection(entityName);
|
||||||
|
String billno = (String) form.getView().getModel().getValue("billno");
|
||||||
|
|
||||||
|
// 获取现有的 UID 列表
|
||||||
|
Set<String> 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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param form
|
||||||
|
* @param attachmentpanelKey
|
||||||
|
* @return
|
||||||
|
* @Description 构建附件map
|
||||||
|
*/
|
||||||
|
private static Map<String, Map<String, Object>> buildAttachmentMap(AbstractBillPlugIn form, String attachmentpanelKey) {
|
||||||
|
Map<String, Map<String, Object>> attachmentMap = new HashMap<>();
|
||||||
|
AttachmentPanel attachmentPanel = form.getView().getControl(attachmentpanelKey);
|
||||||
|
List<Map<String, Object>> attachmentDatas = attachmentPanel.getAttachmentData();
|
||||||
|
|
||||||
|
for (Map<String, Object> 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<String, Object> creator = (Map<String, Object>) attachmentData.get("creator");
|
||||||
|
String creatorName = creator != null ? (String) creator.get("zh_CN") : null;
|
||||||
|
|
||||||
|
// 存储数据
|
||||||
|
Map<String, Object> 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
|
||||||
|
* @Description 更新附件行
|
||||||
|
*/
|
||||||
|
private static void updateExistingAttachment(AbstractBillPlugIn form, DynamicObjectCollection attachmentDetail,
|
||||||
|
String uid, Map<String, Object> 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
|
||||||
|
* @Description 增加新附件行
|
||||||
|
*/
|
||||||
|
private static void createNewAttachment(AbstractBillPlugIn form, String entityName, String uid,
|
||||||
|
Map<String, Object> 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
|
||||||
|
* @Description 附件分录赋值
|
||||||
|
*/
|
||||||
|
private static void setAttachmentValues(AbstractBillPlugIn form, int row, String uid,
|
||||||
|
Map<String, Object> 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);
|
||||||
|
}
|
||||||
|
}
|
@ -26,9 +26,19 @@ dependencies {
|
|||||||
implementation project(':yem-wm-is')
|
implementation project(':yem-wm-is')
|
||||||
// 引入wm云 ct应用模块
|
// 引入wm云 ct应用模块
|
||||||
implementation project(':yem-wm-ct')
|
implementation project(':yem-wm-ct')
|
||||||
|
// 引入wm云 bd应用模块
|
||||||
|
implementation project(':yem-wmzh-csm')
|
||||||
|
|
||||||
|
|
||||||
|
// 引入wm云 bd应用模块
|
||||||
|
implementation project(':yem-wm-bd')
|
||||||
// 引入wm云 bd应用模块
|
// 引入wm云 bd应用模块
|
||||||
implementation project(':yem-wm-bd')
|
implementation project(':yem-wm-bd')
|
||||||
// 引入wm云 sex应用模块
|
// 引入wm云 sex应用模块
|
||||||
implementation project(':yem-wm-sex')
|
implementation project(':yem-wm-sex')
|
||||||
|
|
||||||
|
|
||||||
|
// 引入wmzh云 ii应用模块
|
||||||
|
implementation project(':yem-wmzh-ii')
|
||||||
|
|
||||||
}
|
}
|
Binary file not shown.
@ -0,0 +1,43 @@
|
|||||||
|
package yem.wm.bd.attachmenttype.opplugin.op;
|
||||||
|
|
||||||
|
import kd.bos.dataentity.entity.DynamicObject;
|
||||||
|
import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
|
||||||
|
import kd.bos.entity.plugin.args.AfterOperationArgs;
|
||||||
|
import kd.bos.entity.plugin.args.BeforeOperationArgs;
|
||||||
|
import kd.bos.orm.query.QCP;
|
||||||
|
import kd.bos.orm.query.QFilter;
|
||||||
|
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
||||||
|
import kd.bos.servicehelper.operation.SaveServiceHelper;
|
||||||
|
import yem.base.common.utils.DynamicObjectUtil;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description 附件类型
|
||||||
|
* @Author: LiuHB
|
||||||
|
* @CreateTime: 2025-02-19 10:23
|
||||||
|
*/
|
||||||
|
public class OnlyoneIsdefaultOpPlugin extends AbstractOperationServicePlugIn {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void afterExecuteOperationTransaction(AfterOperationArgs e) {
|
||||||
|
super.afterExecuteOperationTransaction(e);
|
||||||
|
DynamicObject[] attachmenttypes = e.getDataEntities();
|
||||||
|
for (DynamicObject attachmenttype : attachmenttypes) {
|
||||||
|
boolean yemIsdefault = attachmenttype.getBoolean("yem_isdefault");
|
||||||
|
if(yemIsdefault){
|
||||||
|
long id = attachmenttype.getLong("id");
|
||||||
|
DynamicObject yemBill = attachmenttype.getDynamicObject("yem_bill");
|
||||||
|
String selectfields = DynamicObjectUtil.getSelectfields("yem_bd_attachmenttype", false);
|
||||||
|
QFilter qFilter = new QFilter("id", QCP.not_equals, id);
|
||||||
|
qFilter.and("yem_bill.number",QCP.equals,yemBill.getString("number"));
|
||||||
|
DynamicObject[] bdAttachmenttypes = BusinessDataServiceHelper.load("yem_bd_attachmenttype", selectfields, qFilter.toArray());
|
||||||
|
for (DynamicObject bdAttachmenttype : bdAttachmenttypes) {
|
||||||
|
bdAttachmenttype.set("yem_isdefault",false);
|
||||||
|
}
|
||||||
|
SaveServiceHelper.save(bdAttachmenttypes);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
14
yem-wmzh/yem-wmzh-csm/build.gradle
Normal file
14
yem-wmzh/yem-wmzh-csm/build.gradle
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
/*
|
||||||
|
* This is a kingdee cosmic template project that is automatically generated by the Kingdee cosmic development assistant plugin.
|
||||||
|
* If there are any issues during the use process, you can provide feedback to the kingdee developer community website.
|
||||||
|
* Website: https://developer.kingdee.com/developer?productLineId=29
|
||||||
|
* Author: liebin.zheng
|
||||||
|
* Generate Date: 2025-02-07 14:05:03
|
||||||
|
*/
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
api project(':yem-base-common')
|
||||||
|
// api project(':yem-base-helper')
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
16
yem-wmzh/yem-wmzh-csm/build/tmp/jar/MANIFEST.MF
Normal file
16
yem-wmzh/yem-wmzh-csm/build/tmp/jar/MANIFEST.MF
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
Manifest-Version: 1.0
|
||||||
|
Jar-Id:
|
||||||
|
Project-Name: yem-wmzh-csm
|
||||||
|
Build-Tool: Gradle 7.6.3
|
||||||
|
Build-Date: 2025-02-15 16:08:12
|
||||||
|
Built-By: Kingdee Cosmic Developer Tools
|
||||||
|
Build-Num: 20250215160812478
|
||||||
|
App-Name:
|
||||||
|
Git-Branch: yem_rabbit_lhb
|
||||||
|
Cloud-Name:
|
||||||
|
Group-Name: yem.cosmic
|
||||||
|
Bundle-Version: 1.0.0
|
||||||
|
Git-Commit-Hash: 678508f62693a02be59f8ff86bf43f2731423ab1
|
||||||
|
Build-Image:
|
||||||
|
Build-Jdk: 1.8.0_201
|
||||||
|
|
2
yem-wmzh/yem-wmzh-csm/build/tmp/sourcesJar/MANIFEST.MF
Normal file
2
yem-wmzh/yem-wmzh-csm/build/tmp/sourcesJar/MANIFEST.MF
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
Manifest-Version: 1.0
|
||||||
|
|
@ -0,0 +1,170 @@
|
|||||||
|
package yem.wmzh.csm.customeraccess.dynamic;
|
||||||
|
|
||||||
|
import com.alibaba.nacos.common.utils.StringUtils;
|
||||||
|
import kd.bos.dataentity.entity.DynamicObject;
|
||||||
|
import kd.bos.dataentity.entity.ILocaleString;
|
||||||
|
import kd.bos.entity.datamodel.IDataModel;
|
||||||
|
import kd.bos.entity.datamodel.events.PropertyChangedArgs;
|
||||||
|
import kd.bos.form.FormShowParameter;
|
||||||
|
import kd.bos.form.IFormView;
|
||||||
|
import kd.bos.form.control.Control;
|
||||||
|
import kd.bos.form.plugin.AbstractFormPlugin;
|
||||||
|
import kd.bos.orm.query.QCP;
|
||||||
|
import kd.bos.orm.query.QFilter;
|
||||||
|
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
||||||
|
import yem.base.common.utils.YEM;
|
||||||
|
|
||||||
|
import java.util.EventObject;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description 客商地址动态表单插件
|
||||||
|
* @Author: LiuHB
|
||||||
|
* @CreateTime: 2025-02-10 10:53
|
||||||
|
*/
|
||||||
|
public class CusdressFormPlugin extends AbstractFormPlugin {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 在此事件,可以侦听各个控件的插件事件
|
||||||
|
* @function 1.侦听确认和取消按钮
|
||||||
|
* @purposes 用户与界面上的控件进行交互时,触发此事件。
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void registerListener(EventObject e) {
|
||||||
|
super.registerListener(e);
|
||||||
|
this.addClickListeners("btnok", "btncancel"); // 侦听确认和取消按钮
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 界面初始化
|
||||||
|
* @function 加载客商准入单数据到动态表单
|
||||||
|
* @purposes 对已创建好的模型数据包进一步加工
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void afterCreateNewData(EventObject e) {
|
||||||
|
super.afterCreateNewData(e);
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void propertyChanged(PropertyChangedArgs e) {
|
||||||
|
super.propertyChanged(e);
|
||||||
|
IFormView view = this.getView();
|
||||||
|
IDataModel model = this.getModel();
|
||||||
|
String name = e.getProperty().getName();
|
||||||
|
switch (name) {
|
||||||
|
case "yem_addressnumber":
|
||||||
|
DynamicObject bd_address = BusinessDataServiceHelper.loadSingle("bd_address", new QFilter[]{new QFilter("number", QCP.equals, (String) model.getValue("yem_addressnumber"))});
|
||||||
|
if(null!= bd_address){
|
||||||
|
model.setValue("yem_addressnumber",null);
|
||||||
|
view.showErrorNotification("编码重复请重新填写");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 插件可以在此相应点击事件,如弹出单独的编辑界面。
|
||||||
|
* @function 回填客商地址基础资料数据到分录
|
||||||
|
* @purposes 点击文本字段的按钮时,触发此事件
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void click(EventObject evt) {
|
||||||
|
super.click(evt);
|
||||||
|
// 获取被点击的控件对象
|
||||||
|
Control source = (Control) evt.getSource();
|
||||||
|
String key = source.getKey();
|
||||||
|
if (StringUtils.equals("btnok", key)) {
|
||||||
|
//回传地址信息
|
||||||
|
setaddressinformation();
|
||||||
|
this.getView().close();
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
this.getView().close();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 初始化动态表单数据
|
||||||
|
* @purposes 加载客商准入单数据到动态表单
|
||||||
|
*/
|
||||||
|
|
||||||
|
private void init() {
|
||||||
|
FormShowParameter showParameter = this.getView().getFormShowParameter();
|
||||||
|
IDataModel model = this.getModel();
|
||||||
|
Map<String, Object> maps = showParameter.getCustomParams();
|
||||||
|
Map<String, Object> parenrow = (Map) maps.get("row");//父页面选中行
|
||||||
|
model.setValue("yem_addressnumber",parenrow.get("yem_addressnumber"));
|
||||||
|
model.setValue("yem_addressname",parenrow.get("yem_addressname"));
|
||||||
|
Map<String,Object> yemTradeterms = (Map<String,Object>)parenrow.get("yem_tradeterms");
|
||||||
|
Long yemTradetermsid = null != yemTradeterms ? (Long)yemTradeterms.get("id") : 0L;
|
||||||
|
model.setValue("yem_tradeterms",yemTradetermsid);
|
||||||
|
model.setValue("yem_clearanceco",parenrow.get("yem_clearanceco"));
|
||||||
|
model.setValue("yem_forwarderco",parenrow.get("yem_forwarderco"));
|
||||||
|
model.setValue("yem_addressphone",parenrow.get("yem_addressphone"));
|
||||||
|
model.setValue("yem_zipcode",parenrow.get("yem_zipcode"));
|
||||||
|
model.setValue("yem_linkman",parenrow.get("yem_linkman"));
|
||||||
|
Map<String,Object> yemTimezone = ( Map<String,Object>)parenrow.get("yem_timezone");
|
||||||
|
long yemTimezoneid = null != yemTimezone ? (Long) yemTimezone.get("id") : 0L;
|
||||||
|
model.setValue("yem_timezone",yemTimezoneid);
|
||||||
|
model.setValue("yem_addressenable",parenrow.get("yem_addressenable"));
|
||||||
|
model.setValue("yem_addressdefault",parenrow.get("yem_addressdefault"));
|
||||||
|
String admindivision = (String) parenrow.get("yem_admindivision");
|
||||||
|
Long yemadmindivisionid = 0L;
|
||||||
|
if(!YEM.isEmpty(admindivision)){
|
||||||
|
yemadmindivisionid = Long.valueOf(admindivision);
|
||||||
|
}
|
||||||
|
model.setValue("yem_admindivision",yemadmindivisionid);
|
||||||
|
model.setValue("yem_detailaddress",parenrow.get("yem_detailaddress"));
|
||||||
|
Map<String,Object> yemCustomeraddrsspur = (Map<String,Object>)parenrow.get("yem_customeraddrsspur");
|
||||||
|
Long yemCustomeraddrsspurid = null != yemCustomeraddrsspur ? (Long)yemCustomeraddrsspur.get("id") : 0L;
|
||||||
|
model.setValue("yem_customeraddrsspur",yemCustomeraddrsspurid);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 回传地址信息到客商准入单
|
||||||
|
*/
|
||||||
|
private void setaddressinformation() {
|
||||||
|
IDataModel model = this.getModel();
|
||||||
|
FormShowParameter showParameter = this.getView().getFormShowParameter();
|
||||||
|
Map<String, Object> maps = showParameter.getCustomParams();
|
||||||
|
Map<String, Object> parenrow = (Map) maps.get("row");//父页面选中行
|
||||||
|
int parenseq = (int) parenrow.get("seq");//父页面选中行号
|
||||||
|
int indexof = parenseq - 1;
|
||||||
|
Map<String, Object> hashMap = new HashMap<>();
|
||||||
|
String yemAddressnumber = (String) model.getValue("yem_addressnumber");//编码
|
||||||
|
ILocaleString yemAddressname = (ILocaleString) model.getValue("yem_addressname");//名称
|
||||||
|
DynamicObject yemTradeterms = (DynamicObject) model.getValue("yem_tradeterms");//贸易术语
|
||||||
|
String yemClearanceco = (String) model.getValue("yem_clearanceco");//清关公司
|
||||||
|
String yemForwarderco = (String) model.getValue("yem_forwarderco");//货代公司
|
||||||
|
ILocaleString yemAddressphone = (ILocaleString) model.getValue("yem_addressphone");//联系电话
|
||||||
|
String yemZipcode = (String) model.getValue("yem_zipcode");//邮政编码
|
||||||
|
String yemLinkman = (String) model.getValue("yem_linkman");//传真
|
||||||
|
DynamicObject yemTimezone = (DynamicObject) model.getValue("yem_timezone");//时区
|
||||||
|
String yemAddressenable = (String) model.getValue("yem_addressenable");//使用状态
|
||||||
|
Boolean yemAddressdefault = (Boolean) model.getValue("yem_addressdefault");//默认
|
||||||
|
String yemAdmindivision = (String) model.getValue("yem_admindivision");//行政区划
|
||||||
|
ILocaleString yemDetailaddress = (ILocaleString) model.getValue("yem_detailaddress");//详细地址
|
||||||
|
DynamicObject yemCustomeraddrsspur = (DynamicObject) model.getValue("yem_customeraddrsspur");//客户地址用途
|
||||||
|
hashMap.put("yem_associatedaddress", yemAddressname);
|
||||||
|
hashMap.put("yem_addressnumber", yemAddressnumber);
|
||||||
|
hashMap.put("yem_addressname", yemAddressname);
|
||||||
|
hashMap.put("yem_tradeterms", yemTradeterms);
|
||||||
|
hashMap.put("yem_clearanceco", yemClearanceco);
|
||||||
|
hashMap.put("yem_forwarderco", yemForwarderco);
|
||||||
|
hashMap.put("yem_addressphone", yemAddressphone);
|
||||||
|
hashMap.put("yem_zipcode", yemZipcode);
|
||||||
|
hashMap.put("yem_linkman", yemLinkman);
|
||||||
|
hashMap.put("yem_timezone", yemTimezone);
|
||||||
|
hashMap.put("yem_addressenable", yemAddressenable);
|
||||||
|
hashMap.put("yem_addressdefault", yemAddressdefault);
|
||||||
|
hashMap.put("yem_admindivision", yemAdmindivision);
|
||||||
|
hashMap.put("yem_detailaddress", yemDetailaddress);
|
||||||
|
hashMap.put("yem_customeraddrsspur", yemCustomeraddrsspur);
|
||||||
|
hashMap.put("indexof", indexof);
|
||||||
|
this.getView().returnDataToParent(hashMap);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,335 @@
|
|||||||
|
package yem.wmzh.csm.customeraccess.from;
|
||||||
|
|
||||||
|
import com.alibaba.druid.util.StringUtils;
|
||||||
|
import kd.bos.bill.AbstractBillPlugIn;
|
||||||
|
import kd.bos.bill.OperationStatus;
|
||||||
|
import kd.bos.dataentity.entity.DynamicObject;
|
||||||
|
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
||||||
|
import kd.bos.dataentity.entity.ILocaleString;
|
||||||
|
import kd.bos.entity.datamodel.IDataModel;
|
||||||
|
import kd.bos.entity.datamodel.events.ChangeData;
|
||||||
|
import kd.bos.entity.datamodel.events.PropertyChangedArgs;
|
||||||
|
import kd.bos.form.CloseCallBack;
|
||||||
|
import kd.bos.form.FormShowParameter;
|
||||||
|
import kd.bos.form.IFormView;
|
||||||
|
import kd.bos.form.ShowType;
|
||||||
|
import kd.bos.form.control.Control;
|
||||||
|
import kd.bos.form.control.EntryGrid;
|
||||||
|
import kd.bos.form.events.ClosedCallBackEvent;
|
||||||
|
import kd.bos.orm.query.QCP;
|
||||||
|
import kd.bos.orm.query.QFilter;
|
||||||
|
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
||||||
|
import kd.bos.servicehelper.user.UserServiceHelper;
|
||||||
|
import yem.base.common.utils.YEM;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description 客商准入单表单插件
|
||||||
|
* @Author: LiuHB
|
||||||
|
* @CreateTime: 2025-02-07 14:40
|
||||||
|
*/
|
||||||
|
public class CustomeraccessBillPlugin extends AbstractBillPlugIn {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 在此事件,可以侦听各个控件的插件事件
|
||||||
|
* @function 1.侦听【客商地址】字段点击
|
||||||
|
* @purposes 用户与界面上的控件进行交互时,触发此事件。
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void registerListener(EventObject e) {
|
||||||
|
super.registerListener(e);
|
||||||
|
this.addClickListeners("yem_associatedaddress"); //监听【客商地址】
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 界面初始化
|
||||||
|
* @function 根据当前人员携带所在部门
|
||||||
|
* @purposes 对已创建好的模型数据包进一步加工
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void afterCreateNewData(EventObject e) {
|
||||||
|
super.afterCreateNewData(e);
|
||||||
|
IDataModel model = this.getModel();
|
||||||
|
IFormView view = this.getView();
|
||||||
|
//获取当前登录人所在部门
|
||||||
|
Long dptid = getdepartmentid();
|
||||||
|
model.setValue("yem_department", dptid);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 根据当前登陆人获取所在部门
|
||||||
|
* @function 获取当前登录人部门id
|
||||||
|
* @purposes 客商准入单初始化【部门】赋值
|
||||||
|
*/
|
||||||
|
|
||||||
|
private Long getdepartmentid() {
|
||||||
|
// 获取当前登录人id
|
||||||
|
long userId = UserServiceHelper.getCurrentUserId();
|
||||||
|
//查询人员
|
||||||
|
DynamicObject user = BusinessDataServiceHelper.loadSingle("bos_user", new QFilter[]{new QFilter("id", QCP.equals, userId)});
|
||||||
|
DynamicObjectCollection entryentity = user.getDynamicObjectCollection("entryentity");
|
||||||
|
Long dptid = 0L;
|
||||||
|
if (entryentity.size() > 0) {
|
||||||
|
for (DynamicObject userow : entryentity) {
|
||||||
|
boolean ispartjob = userow.getBoolean("ispartjob");
|
||||||
|
if(!ispartjob){
|
||||||
|
DynamicObject dpt = (DynamicObject) userow.get("dpt");
|
||||||
|
dptid = null != dpt ? dpt.getLong("id") : null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return dptid;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: 值改变事件
|
||||||
|
* @function 1.内部业务单元校验
|
||||||
|
* 2.去除客商名称中的空格,如果都是中文字符去除所有空格,包含其他字符则去除前后空格
|
||||||
|
* 3.去除客商英文名称前后空格
|
||||||
|
* @purposes 通知插件字段发生了改变,可以同步调整其他字段值
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void propertyChanged(PropertyChangedArgs e) {
|
||||||
|
super.propertyChanged(e);
|
||||||
|
String key = e.getProperty().getName();
|
||||||
|
ChangeData changeData = e.getChangeSet()[0];
|
||||||
|
int index = changeData.getRowIndex();
|
||||||
|
IDataModel model = this.getModel();
|
||||||
|
IFormView view = this.getView();
|
||||||
|
switch (key) {
|
||||||
|
case "yem_internal":
|
||||||
|
case "yem_merchantstname":
|
||||||
|
ILocaleString yemMerchantstnamed = (ILocaleString) this.getModel().getValue("yem_merchantstname");
|
||||||
|
String yemMerchantstnames = yemMerchantstnamed.getLocaleValue();
|
||||||
|
Boolean yemInternal = (Boolean) model.getValue("yem_internal");//内部业务单元
|
||||||
|
String domesticoroverseas = (String)model.getValue("yem_domesticoroverseas");
|
||||||
|
//去除客商名称中的空格
|
||||||
|
String merchantstnames = nameprocessing(yemMerchantstnames,domesticoroverseas);
|
||||||
|
//校验必须有与客商名称匹配的组织
|
||||||
|
matchOrganizations(yemInternal, merchantstnames);
|
||||||
|
break;
|
||||||
|
case "yem_merchantstnames_en":
|
||||||
|
String yemMerchantstnamesEns = (String) this.getModel().getValue("yem_merchantstnames_en");
|
||||||
|
String trimmedString = yemMerchantstnamesEns.trim();
|
||||||
|
this.getModel().setValue("yem_merchantstnames_en", trimmedString);
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 插件可以在此相应点击事件,如弹出单独的编辑界面。
|
||||||
|
* @function 1.弹出{客商地址}动态表单,回填联系人分录
|
||||||
|
* @purposes 点击文本字段的按钮时,触发此事件
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void click(EventObject evt) {
|
||||||
|
super.click(evt);
|
||||||
|
Control c = (Control) evt.getSource();
|
||||||
|
String key = c.getKey();
|
||||||
|
switch (key){
|
||||||
|
case "yem_associatedaddress":
|
||||||
|
addressPasswd("yem_wmzh_cusadress", "yem_associatedaddress");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 弹出{客商地址}动态表单
|
||||||
|
*/
|
||||||
|
private void addressPasswd(String dynamicform, String button) {
|
||||||
|
FormShowParameter showParameter = new FormShowParameter();
|
||||||
|
showParameter.setStatus(OperationStatus.ADDNEW);
|
||||||
|
showParameter.getOpenStyle().setShowType(ShowType.Modal);
|
||||||
|
Map<String, Object> map = this.showInfoForm();
|
||||||
|
showParameter.setCustomParams(map);
|
||||||
|
showParameter.setCloseCallBack(new CloseCallBack(this, button));
|
||||||
|
showParameter.setFormId(dynamicform);
|
||||||
|
this.getView().showForm(showParameter);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 构建向动态表单传递的数据集
|
||||||
|
*/
|
||||||
|
|
||||||
|
private Map<String, Object> showInfoForm() {
|
||||||
|
Map<String, Object> map = new HashMap<>();
|
||||||
|
DynamicObjectCollection yem_contactinfo_e = this.getModel().getEntryEntity("yem_linkmaninfo_e");
|
||||||
|
EntryGrid contactinfo = this.getControl("yem_linkmaninfo_e");
|
||||||
|
int[] selectRows = contactinfo.getSelectRows();
|
||||||
|
if (selectRows != null) {
|
||||||
|
for (int selectRow : selectRows) {
|
||||||
|
DynamicObject yem_contactinfo = yem_contactinfo_e.get(selectRow); // 获取选中行的单据体数据
|
||||||
|
map.put("row", yem_contactinfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 动态表单关闭回调事件
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void closedCallBack(ClosedCallBackEvent closedCallBackEvent) {
|
||||||
|
// super.closedCallBack(closedCallBackEvent);
|
||||||
|
Object returnData = closedCallBackEvent.getReturnData();
|
||||||
|
// 判断标识是否匹配,并验证动态表单返回数据不为空,不验证返回值可能会报空指针
|
||||||
|
if (StringUtils.equals(closedCallBackEvent.getActionId(), "yem_associatedaddress")
|
||||||
|
&& null != closedCallBackEvent.getReturnData()) {
|
||||||
|
// 这里返回对象为Object,可强转成相应的其他类型,
|
||||||
|
HashMap<String, Object> values = (HashMap<String, Object>) returnData;
|
||||||
|
this.setInwardInfo(values);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 分录赋值
|
||||||
|
* @purposes 将动态表单数据回填到对应行上
|
||||||
|
*/
|
||||||
|
|
||||||
|
private void setInwardInfo(Map<String, Object> values) {
|
||||||
|
IDataModel model = this.getModel();
|
||||||
|
int indexof = (int) values.get("indexof");
|
||||||
|
model.setValue("yem_associatedaddress", values.get("yem_addressname"), indexof);
|
||||||
|
model.setValue("yem_addressnumber", values.get("yem_addressnumber"), indexof);
|
||||||
|
model.setValue("yem_addressname", values.get("yem_addressname"), indexof);
|
||||||
|
model.setValue("yem_tradeterms", values.get("yem_tradeterms"), indexof);
|
||||||
|
model.setValue("yem_clearanceco", values.get("yem_clearanceco"), indexof);
|
||||||
|
model.setValue("yem_forwarderco", values.get("yem_forwarderco"), indexof);
|
||||||
|
model.setValue("yem_addressphone", values.get("yem_addressphone"), indexof);
|
||||||
|
model.setValue("yem_zipcode", values.get("yem_zipcode"), indexof);
|
||||||
|
model.setValue("yem_linkman", values.get("yem_linkman"), indexof);
|
||||||
|
model.setValue("yem_timezone", values.get("yem_timezone"), indexof);
|
||||||
|
model.setValue("yem_addressenable", values.get("yem_addressenable"), indexof);
|
||||||
|
model.setValue("yem_addressdefault", values.get("yem_addressdefault"), indexof);
|
||||||
|
model.setValue("yem_admindivision", values.get("yem_admindivision"), indexof);
|
||||||
|
model.setValue("yem_detailaddress", values.get("yem_detailaddress"), indexof);
|
||||||
|
model.setValue("yem_customeraddrsspur", values.get("yem_customeraddrsspur"), indexof);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 去除客商名称中的空格
|
||||||
|
* @function 去除客商名称中的空格, 如果都是中文字符去除所有空格,包含其他字符则去除前后空格
|
||||||
|
*/
|
||||||
|
private String nameprocessing(String yemMerchantstnames, String domesticoroverseas) {
|
||||||
|
String merchantstnames = "";
|
||||||
|
boolean containsValidChars = false;
|
||||||
|
boolean containsChinese = false;
|
||||||
|
// if("A".equals(domesticoroverseas)) {
|
||||||
|
// 检查是否包含中文字符
|
||||||
|
if(null!=yemMerchantstnames) {
|
||||||
|
if("A".equals(domesticoroverseas)) {
|
||||||
|
yemMerchantstnames = yemMerchantstnames.replace("(", "(").replace(")", ")");
|
||||||
|
containsValidChars = yemMerchantstnames.codePoints()
|
||||||
|
.allMatch(codePoint ->
|
||||||
|
(codePoint >= 0x4e00 && codePoint <= 0x9fa5) || // 基本汉字
|
||||||
|
(codePoint >= 0x3400 && codePoint <= 0x4dbf) || // 扩展A
|
||||||
|
(codePoint >= 0xf900 && codePoint <= 0xfaff) || // 兼容汉字
|
||||||
|
(codePoint >= 0x20000 && codePoint <= 0x2a6df) || // 扩展B
|
||||||
|
(codePoint >= 0x2a700 && codePoint <= 0x2b73f) || // 扩展C
|
||||||
|
(codePoint >= 0x2b740 && codePoint <= 0x2b81f) || // 扩展D
|
||||||
|
(codePoint >= 0x2b820 && codePoint <= 0x2ceaf) || // 扩展E
|
||||||
|
(codePoint == 0xFF08 || codePoint == 0xFF09) || // 中文括号 ()
|
||||||
|
(codePoint == 0x0020) // 空格
|
||||||
|
);
|
||||||
|
|
||||||
|
// 检查字符串中是否包含至少一个中文字符
|
||||||
|
containsChinese = yemMerchantstnames.codePoints()
|
||||||
|
.anyMatch(codePoint ->
|
||||||
|
(codePoint >= 0x4e00 && codePoint <= 0x9fa5) || // 基本汉字
|
||||||
|
(codePoint >= 0x3400 && codePoint <= 0x4dbf) || // 扩展A
|
||||||
|
(codePoint >= 0xf900 && codePoint <= 0xfaff) || // 兼容汉字
|
||||||
|
(codePoint >= 0x20000 && codePoint <= 0x2a6df) || // 扩展B
|
||||||
|
(codePoint >= 0x2a700 && codePoint <= 0x2b73f) || // 扩展C
|
||||||
|
(codePoint >= 0x2b740 && codePoint <= 0x2b81f) || // 扩展D
|
||||||
|
(codePoint >= 0x2b820 && codePoint <= 0x2ceaf) // 扩展E
|
||||||
|
);
|
||||||
|
}
|
||||||
|
boolean isValid = containsValidChars && containsChinese;
|
||||||
|
if (isValid) {
|
||||||
|
//字符串全部由中文字符组成
|
||||||
|
//去除客商名称空格
|
||||||
|
merchantstnames = removeSpacesFromString(yemMerchantstnames);
|
||||||
|
this.getModel().setValue("yem_merchantstname", merchantstnames);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
//字符串包含非中文字符
|
||||||
|
merchantstnames = yemMerchantstnames.trim();
|
||||||
|
this.getModel().setValue("yem_merchantstname", merchantstnames);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return merchantstnames;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 去除客商名称空格
|
||||||
|
* @function 删除空格
|
||||||
|
* @purposes 避免客户输入失误
|
||||||
|
*/
|
||||||
|
private String removeSpacesFromString(String yemMerchantstnames) {
|
||||||
|
if (yemMerchantstnames == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
// 去除字符串中的所有空格并返回结果
|
||||||
|
return yemMerchantstnames.replace(" ", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 内部业务单元校验
|
||||||
|
* @function 1.校验必须有与客商名称匹配的组织
|
||||||
|
* 2.校验内部业务单元客商和准入组织名称是否相同
|
||||||
|
* @purposes 确保该客商在系统的行政组织中
|
||||||
|
*/
|
||||||
|
private void matchOrganizations(Boolean yemInternal, String yemMerchantstnames) {
|
||||||
|
IDataModel model = this.getModel();
|
||||||
|
// 如果 内部业务单元 为 false 或 客商中文名称 为空,直接返回
|
||||||
|
if (!yemInternal || YEM.isEmpty(yemMerchantstnames)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//获取当前单据准入组织
|
||||||
|
DynamicObject org = (DynamicObject)model.getValue("org");
|
||||||
|
String name = null != org ? org.getString("name") : "";
|
||||||
|
// 加载行政组织信息
|
||||||
|
List<String> adminOrgNames = loadAdminOrgNames();
|
||||||
|
// 1.检查 客商名称 是否在行政组织列表中
|
||||||
|
if (!adminOrgNames.contains(yemMerchantstnames)) {
|
||||||
|
model.setValue("yem_merchantstname",null);
|
||||||
|
this.getView().showErrorNotification("未找到与之匹配的组织,请重新检查相关信息。");
|
||||||
|
}if(!name.equals(yemMerchantstnames)){
|
||||||
|
model.setValue("yem_merchantstname",null);
|
||||||
|
this.getView().showErrorNotification("该内部业务单元客商:"+yemMerchantstnames+"与准入组织不符,请检查!");
|
||||||
|
}
|
||||||
|
this.getView().updateView();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 获取所有组织名称
|
||||||
|
* @function 查询行政组织
|
||||||
|
* @purposes 辅助方法:加载行政组织名称列表
|
||||||
|
*/
|
||||||
|
public static List<String> loadAdminOrgNames() {
|
||||||
|
String adminOrgFields = "number,name"; // 查询字段:编码和名称
|
||||||
|
DynamicObject[] adminOrgs = BusinessDataServiceHelper.load("bos_adminorg", adminOrgFields, null);
|
||||||
|
|
||||||
|
List<String> adminOrgNames = new ArrayList<>();
|
||||||
|
for (DynamicObject adminOrg : adminOrgs) {
|
||||||
|
String name = adminOrg.getLocaleString("name").getLocaleValue();
|
||||||
|
adminOrgNames.add(name);
|
||||||
|
}
|
||||||
|
return adminOrgNames;
|
||||||
|
}
|
||||||
|
}
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,25 @@
|
|||||||
|
package yem.wmzh.csm.customeraccess.opplugin.op;
|
||||||
|
|
||||||
|
import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
|
||||||
|
import kd.bos.entity.plugin.AddValidatorsEventArgs;
|
||||||
|
import yem.wmzh.csm.customeraccess.opplugin.validator.CustomeraccessSubmitValidator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description 客商准入单提交校验及操作功能
|
||||||
|
* @Author: LiuHB
|
||||||
|
* @CreateTime: 2025-02-07 17:23
|
||||||
|
*/
|
||||||
|
public class CustomeraccessSubmitOpPlugin extends AbstractOperationServicePlugIn {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 自定义操作校验器
|
||||||
|
* @function 1.【内部业务单元】=true,且字段【境内/境外】=境内时,统一社会信用代码必填
|
||||||
|
* @purposes 构建好操作校验器之后,操作校验之前,触发校验
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAddValidators(AddValidatorsEventArgs e) {
|
||||||
|
super.onAddValidators(e);
|
||||||
|
e.addValidator(new CustomeraccessSubmitValidator());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,93 @@
|
|||||||
|
package yem.wmzh.csm.customeraccess.opplugin.validator;
|
||||||
|
|
||||||
|
import kd.bos.dataentity.entity.DynamicObject;
|
||||||
|
import kd.bos.dataentity.entity.ILocaleString;
|
||||||
|
import kd.bos.entity.ExtendedDataEntity;
|
||||||
|
import kd.bos.entity.validate.AbstractValidator;
|
||||||
|
import yem.base.common.utils.YEM;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static yem.wmzh.csm.customeraccess.from.CustomeraccessBillPlugin.loadAdminOrgNames;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description 客商准入单提交校验
|
||||||
|
* @Author: LiuHB
|
||||||
|
* @CreateTime: 2025-02-07 17:26
|
||||||
|
*/
|
||||||
|
public class CustomeraccessSubmitValidator extends AbstractValidator {
|
||||||
|
/**
|
||||||
|
* @Description: 自定义校验器
|
||||||
|
* @function 1.【内部业务单元】=true,且字段【境内/境外】=境内时,统一社会信用代码必填
|
||||||
|
* 2.检查 客商名称 是否在行政组织列表中
|
||||||
|
* 3.检查客商名称 是否和准入组织相同
|
||||||
|
* @purposes 重写系统validate方法在提交节点增加控制
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void validate() {
|
||||||
|
// 如果操作键不是 "submit",直接返回
|
||||||
|
if (!"submit".equals(this.getOperateKey())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ExtendedDataEntity[] dataEntities = this.getDataEntities();
|
||||||
|
// 遍历每个数据实体并进行校验
|
||||||
|
for (ExtendedDataEntity entity : dataEntities) {
|
||||||
|
//【内部业务单元】=true,且字段【境内/境外】=境内时,统一社会信用代码必填
|
||||||
|
validateCustomerInternalInfo(entity.getDataEntity(), entity);
|
||||||
|
//客商名称校验
|
||||||
|
Calibratecustomername(entity.getDataEntity(), entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Calibratecustomername(DynamicObject dataEntity, ExtendedDataEntity entity) {
|
||||||
|
String yemMerchantstnamed = dataEntity.getLocaleString("yem_merchantstname").getLocaleValue();
|
||||||
|
Boolean yemInternal = (Boolean) dataEntity.getBoolean("yem_internal");//内部业务单元
|
||||||
|
//校验必须有与客商名称匹配的组织
|
||||||
|
matchOrganizations(yemInternal, dataEntity,yemMerchantstnamed,entity);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private void matchOrganizations(Boolean yemInternal, DynamicObject dataEntity,String yemMerchantstnamed, ExtendedDataEntity entity) {
|
||||||
|
// 如果 内部业务单元 为 false 或 客商中文名称 为空,直接返回
|
||||||
|
if (!yemInternal || YEM.isEmpty(yemMerchantstnamed)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//获取当前单据准入组织
|
||||||
|
DynamicObject org = (DynamicObject)dataEntity.getDynamicObject("org");
|
||||||
|
String name = null != org ? org.getString("name") : "";
|
||||||
|
// 加载行政组织信息
|
||||||
|
List<String> adminOrgNames = loadAdminOrgNames();
|
||||||
|
// 1.检查 客商名称 是否在行政组织列表中
|
||||||
|
//2.检查客商名称 是否和准入组织相同
|
||||||
|
if (!adminOrgNames.contains(yemMerchantstnamed)) {
|
||||||
|
|
||||||
|
this.addMessage(entity,"未找到与之匹配的组织,请重新检查相关信息。");
|
||||||
|
}if(!name.equals(yemMerchantstnamed)){
|
||||||
|
|
||||||
|
this.addMessage(entity,"该内部业务单元客商:"+yemMerchantstnamed+"与准入组织不符,请检查!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 校验客户内部信息
|
||||||
|
*/
|
||||||
|
private void validateCustomerInternalInfo(DynamicObject customerAccess, ExtendedDataEntity entity) {
|
||||||
|
// 获取内部业务单元、境内/境外、统一社会信用代码
|
||||||
|
boolean yemInternal = customerAccess.getBoolean("yem_internal");
|
||||||
|
String domesticOrOverseas = customerAccess.getString("yem_domesticoroverseas");
|
||||||
|
String societyCreditCode = customerAccess.getString("yem_societycreditcode");
|
||||||
|
// 如果是内部业务单元且位于境内,检查统一社会信用代码是否为空
|
||||||
|
if (isInternalAndDomestic(yemInternal, domesticOrOverseas) && YEM.isEmpty(societyCreditCode)) {
|
||||||
|
this.addMessage(entity, "请填写【统一社会信用代码】");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 判断是否为内部业务单元且位于境内
|
||||||
|
*/
|
||||||
|
private boolean isInternalAndDomestic(boolean yemInternal, String domesticOrOverseas) {
|
||||||
|
return yemInternal && "A".equals(domesticOrOverseas);
|
||||||
|
}
|
||||||
|
}
|
14
yem-wmzh/yem-wmzh-ii/build.gradle
Normal file
14
yem-wmzh/yem-wmzh-ii/build.gradle
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
/*
|
||||||
|
* This is a kingdee cosmic template project that is automatically generated by the Kingdee cosmic development assistant plugin.
|
||||||
|
* If there are any issues during the use process, you can provide feedback to the kingdee developer community website.
|
||||||
|
* Website: https://developer.kingdee.com/developer?productLineId=29
|
||||||
|
* Author: liebin.zheng
|
||||||
|
* Generate Date: 2025-02-18 17:19:05
|
||||||
|
*/
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
api project(':yem-base-common')
|
||||||
|
// api project(':yem-base-helper')
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Binary file not shown.
Binary file not shown.
@ -0,0 +1,231 @@
|
|||||||
|
package yem.wmzh.ii.utils;
|
||||||
|
|
||||||
|
import org.json.simple.JSONObject;
|
||||||
|
import org.json.simple.parser.JSONParser;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.DataOutputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description Http连接
|
||||||
|
* @Author: LiuHB
|
||||||
|
* @CreateTime: 2025-02-18 17:28
|
||||||
|
*/
|
||||||
|
public class InterfaceCallspublicMethods {
|
||||||
|
/**
|
||||||
|
* @Description: 访问接口GET
|
||||||
|
* @param url 接口地址(带请求参数)
|
||||||
|
* @param info 入参信息
|
||||||
|
* @param accessToken 密钥
|
||||||
|
* @return java.lang.String 返回结果json
|
||||||
|
*/
|
||||||
|
|
||||||
|
public static String sendGetRequest(String url, Map<String,Object> info,String accessToken) {
|
||||||
|
|
||||||
|
|
||||||
|
// // 构建请求参数
|
||||||
|
// StringBuilder params = new StringBuilder();
|
||||||
|
// params.append("key=").append(URLEncoder.encode(key, "UTF-8"));
|
||||||
|
// params.append("&address=").append(URLEncoder.encode(address, "UTF-8"));
|
||||||
|
// if (city != null && !city.isEmpty()) {
|
||||||
|
// params.append("&city=").append(URLEncoder.encode(city, "UTF-8"));
|
||||||
|
// }
|
||||||
|
// params.append("&output=json"); // 请求返回类型为JSON
|
||||||
|
//
|
||||||
|
// // 创建URL对象
|
||||||
|
// URL url = new URL(API_URL + "?" + params.toString());
|
||||||
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
URL urlObj = new URL(url);
|
||||||
|
HttpURLConnection connection = (HttpURLConnection) urlObj.openConnection();
|
||||||
|
|
||||||
|
// 设置请求方法为 GET
|
||||||
|
connection.setRequestMethod("GET");
|
||||||
|
connection.setRequestProperty("Content-Type", "application/json;charset=UTF-8");
|
||||||
|
connection.setRequestProperty("Authorization", "Bearer " + accessToken); // 添加 accessToken 到 Authorization 头部
|
||||||
|
|
||||||
|
// 获取响应状态码
|
||||||
|
int responseCode = connection.getResponseCode();
|
||||||
|
if (responseCode == HttpURLConnection.HTTP_OK) { // 成功
|
||||||
|
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
|
||||||
|
String line;
|
||||||
|
StringBuilder response = new StringBuilder();
|
||||||
|
while ((line = reader.readLine()) != null) {
|
||||||
|
response.append(line);
|
||||||
|
}
|
||||||
|
reader.close();
|
||||||
|
return response.toString();
|
||||||
|
} else {
|
||||||
|
// 处理非 200 的状态码
|
||||||
|
return "GET请求失败,响应码: " + responseCode;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 访问接口PUT
|
||||||
|
* @param url 接口地址
|
||||||
|
* @param parameters 请求体
|
||||||
|
* @param accessToken 密钥
|
||||||
|
* @return java.lang.String 返回结果json
|
||||||
|
*/
|
||||||
|
|
||||||
|
public static String sendPutRequest(String url, String parameters, String accessToken) {
|
||||||
|
try {
|
||||||
|
URL urlObj = new URL(url);
|
||||||
|
HttpURLConnection connection = (HttpURLConnection) urlObj.openConnection();
|
||||||
|
|
||||||
|
// 设置请求方法为 PUT
|
||||||
|
connection.setRequestMethod("PUT");
|
||||||
|
connection.setRequestProperty("Content-Type", "application/json;charset=UTF-8");
|
||||||
|
connection.setRequestProperty("Authorization", "Bearer " + accessToken); // 添加 accessToken 到 Authorization 头部
|
||||||
|
connection.setDoOutput(true);
|
||||||
|
|
||||||
|
// 写入请求体
|
||||||
|
DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream());
|
||||||
|
outputStream.write(parameters.getBytes("UTF-8"));
|
||||||
|
outputStream.flush();
|
||||||
|
outputStream.close();
|
||||||
|
|
||||||
|
// 读取响应
|
||||||
|
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
|
||||||
|
String line;
|
||||||
|
StringBuffer response = new StringBuffer();
|
||||||
|
while ((line = reader.readLine()) != null) {
|
||||||
|
response.append(line);
|
||||||
|
}
|
||||||
|
reader.close();
|
||||||
|
|
||||||
|
return response.toString();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 访问接口post
|
||||||
|
* @param url 接口地址
|
||||||
|
* @param requestBody 请求体
|
||||||
|
* @param accessToken 密钥
|
||||||
|
* @return java.lang.String 返回结果json
|
||||||
|
*/
|
||||||
|
public static String sendPostRequests(String url, String requestBody, String accessToken) throws Exception {
|
||||||
|
URL obj = new URL(url);
|
||||||
|
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
|
||||||
|
con.setRequestMethod("POST");
|
||||||
|
con.setRequestProperty("Content-Type", "application/json");
|
||||||
|
con.setRequestProperty("Authorization", "Bearer " + accessToken); // 添加 accessToken 到 Authorization 头部
|
||||||
|
con.setDoOutput(true);
|
||||||
|
OutputStream os = con.getOutputStream();
|
||||||
|
os.write(requestBody.getBytes());
|
||||||
|
os.flush();
|
||||||
|
os.close();
|
||||||
|
|
||||||
|
BufferedReader in;
|
||||||
|
if (con.getResponseCode() >= 400) {
|
||||||
|
in = new BufferedReader(new InputStreamReader(con.getErrorStream()));
|
||||||
|
} else {
|
||||||
|
in = new BufferedReader(new InputStreamReader(con.getInputStream()));
|
||||||
|
}
|
||||||
|
String inputLine;
|
||||||
|
StringBuilder response = new StringBuilder();
|
||||||
|
|
||||||
|
while ((inputLine = in.readLine()) != null) {
|
||||||
|
response.append(inputLine);
|
||||||
|
}
|
||||||
|
in.close();
|
||||||
|
|
||||||
|
return response.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 访问接口DELETE
|
||||||
|
* @param url 接口地址
|
||||||
|
* @param accessToken 密钥
|
||||||
|
* @return java.lang.String 返回结果json * @return java.lang.String 返回结果json
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
public static String sendDeleteRequest(String url, String accessToken) {
|
||||||
|
try {
|
||||||
|
URL urlObj = new URL(url);
|
||||||
|
HttpURLConnection connection = (HttpURLConnection) urlObj.openConnection();
|
||||||
|
|
||||||
|
// 设置请求方法为 DELETE
|
||||||
|
connection.setRequestMethod("DELETE");
|
||||||
|
connection.setRequestProperty("Content-Type", "application/json;charset=UTF-8");
|
||||||
|
connection.setRequestProperty("Authorization", "Bearer " + accessToken); // 添加 accessToken 到 Authorization 头部
|
||||||
|
|
||||||
|
// 获取响应状态码
|
||||||
|
int responseCode = connection.getResponseCode();
|
||||||
|
if (responseCode == HttpURLConnection.HTTP_NO_CONTENT) { // 成功删除
|
||||||
|
return "DELETE请求成功,响应码: " + responseCode;
|
||||||
|
} else {
|
||||||
|
// 处理非 204 的状态码
|
||||||
|
return "DELETE请求失败,响应码: " + responseCode;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取accessToken
|
||||||
|
* @param username
|
||||||
|
* @param password
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String loginAndGetAccessToken(String username, String password) {
|
||||||
|
try {
|
||||||
|
String url = "http://10.64.111.165/admin-api/system/auth/login";
|
||||||
|
String requestBody = "{\"username\": \"" + username + "\", \"password\": \"" + password + "\"}";
|
||||||
|
|
||||||
|
URL endpoint = new URL(url);
|
||||||
|
HttpURLConnection connection = (HttpURLConnection) endpoint.openConnection();
|
||||||
|
connection.setRequestMethod("POST");
|
||||||
|
connection.setRequestProperty("Content-Type", "application/json");
|
||||||
|
connection.setDoOutput(true);
|
||||||
|
|
||||||
|
try (OutputStream os = connection.getOutputStream()) {
|
||||||
|
byte[] input = requestBody.getBytes("utf-8");
|
||||||
|
os.write(input, 0, input.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
try (BufferedReader br = new BufferedReader(
|
||||||
|
new InputStreamReader(connection.getInputStream(), "utf-8"))) {
|
||||||
|
StringBuilder response = new StringBuilder();
|
||||||
|
String responseLine = null;
|
||||||
|
while ((responseLine = br.readLine()) != null) {
|
||||||
|
response.append(responseLine.trim());
|
||||||
|
}
|
||||||
|
JSONParser parser = new JSONParser();
|
||||||
|
JSONObject jsonResponse = (JSONObject) parser.parse(response.toString());
|
||||||
|
JSONObject data = (JSONObject) jsonResponse.get("data");
|
||||||
|
String accessToken = (String) data.get("accessToken");
|
||||||
|
return accessToken;
|
||||||
|
} finally {
|
||||||
|
connection.disconnect();
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user