146 lines
5.8 KiB
Java
146 lines
5.8 KiB
Java
|
package shkd.repc.resm.button;
|
||
|
|
||
|
import kd.bos.dataentity.entity.DynamicObject;
|
||
|
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
||
|
import kd.bos.form.control.events.BeforeItemClickEvent;
|
||
|
import kd.bos.form.control.events.ItemClickEvent;
|
||
|
import kd.bos.list.plugin.AbstractListPlugin;
|
||
|
import kd.bos.logging.Log;
|
||
|
import kd.bos.logging.LogFactory;
|
||
|
import kd.bos.orm.query.QCP;
|
||
|
import kd.bos.orm.query.QFilter;
|
||
|
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
||
|
import kd.bos.servicehelper.operation.SaveServiceHelper;
|
||
|
import kd.sdk.plugin.Plugin;
|
||
|
|
||
|
import java.util.Map;
|
||
|
|
||
|
/**
|
||
|
* 供应商信息修复按钮
|
||
|
*/
|
||
|
public class SupplierInfoFixeButtonPlugin extends AbstractListPlugin implements Plugin {
|
||
|
|
||
|
private final static Log Logger = LogFactory.getLog(SupplierInfoFixeButtonPlugin.class);
|
||
|
|
||
|
@Override
|
||
|
public void beforeItemClick(BeforeItemClickEvent evt) {
|
||
|
super.beforeItemClick(evt);
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void itemClick(ItemClickEvent evt) {
|
||
|
super.itemClick(evt);
|
||
|
|
||
|
String key = evt.getItemKey();
|
||
|
if (!"qeug_fixesupplier".equalsIgnoreCase(key)) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
// 1. 查询所有已审核、可用状态的正式供应商
|
||
|
QFilter qFilter = new QFilter("status", QCP.equals, "C")
|
||
|
.and(new QFilter("enable", QCP.equals, "1"));
|
||
|
Map<Object, DynamicObject> supplierMap = BusinessDataServiceHelper.loadFromCache(
|
||
|
"resm_official_supplier", qFilter.toArray());
|
||
|
|
||
|
if (supplierMap == null || supplierMap.isEmpty()) {
|
||
|
this.getView().showMessage("没有找到符合条件的供应商数据");
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
// 加载默认供应商分类
|
||
|
DynamicObject defaultGroup = BusinessDataServiceHelper.loadSingle(
|
||
|
"bd_suppliergroup",
|
||
|
new QFilter("number", QCP.equals, "GYSFL-202410-08").toArray());
|
||
|
|
||
|
// 初始化消息构建器
|
||
|
StringBuilder successMessage = new StringBuilder("成功修复以下供应商的分录数据:\n");
|
||
|
StringBuilder errorMessage = new StringBuilder("以下供应商处理失败:\n");
|
||
|
|
||
|
int successCount = 0;
|
||
|
int skipCount = 0;
|
||
|
int errorCount = 0;
|
||
|
|
||
|
for (DynamicObject dynamicObject : supplierMap.values()) {
|
||
|
String supplierNumber = dynamicObject.getString("number");
|
||
|
|
||
|
try {
|
||
|
boolean hasGroup = !dynamicObject.getDynamicObjectCollection("apt_group").isEmpty();
|
||
|
DynamicObjectCollection entry_org = dynamicObject.getDynamicObjectCollection("entry_org");
|
||
|
|
||
|
if (entry_org == null || entry_org.isEmpty()) {
|
||
|
skipCount++;
|
||
|
continue;
|
||
|
}
|
||
|
|
||
|
boolean needProcess = false;
|
||
|
|
||
|
// 检查是否需要处理
|
||
|
for (DynamicObject object : entry_org) {
|
||
|
DynamicObjectCollection entry_org_group = object.getDynamicObjectCollection("entry_org_group");
|
||
|
if (entry_org_group == null || entry_org_group.isEmpty()) {
|
||
|
needProcess = true;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (!needProcess) {
|
||
|
skipCount++;
|
||
|
continue;
|
||
|
}
|
||
|
|
||
|
// 处理数据
|
||
|
for (DynamicObject object : entry_org) {
|
||
|
DynamicObjectCollection entry_org_group = object.getDynamicObjectCollection("entry_org_group");
|
||
|
if (entry_org_group == null || entry_org_group.isEmpty()) {
|
||
|
if (hasGroup) {
|
||
|
for (DynamicObject group : dynamicObject.getDynamicObjectCollection("apt_group")) {
|
||
|
DynamicObject supplierObj = group.getDynamicObject("fbasedataid");
|
||
|
DynamicObject newObject = entry_org_group.addNew();
|
||
|
newObject.set("suppliergroup", supplierObj);
|
||
|
newObject.set("examstatus", "NOT_EXAM");
|
||
|
newObject.set("qualifiedstatus", "1");
|
||
|
newObject.set("frozenstatus", "1");
|
||
|
}
|
||
|
} else {
|
||
|
DynamicObject newObject = entry_org_group.addNew();
|
||
|
newObject.set("suppliergroup", defaultGroup);
|
||
|
newObject.set("examstatus", "NOT_EXAM");
|
||
|
newObject.set("qualifiedstatus", "1");
|
||
|
newObject.set("frozenstatus", "1");
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// 保存数据
|
||
|
SaveServiceHelper.save(new DynamicObject[]{dynamicObject});
|
||
|
successCount++;
|
||
|
successMessage.append(supplierNumber).append("\n");
|
||
|
|
||
|
} catch (Exception e) {
|
||
|
errorCount++;
|
||
|
errorMessage.append(supplierNumber)
|
||
|
.append(" - 错误原因: ")
|
||
|
.append(e.getMessage())
|
||
|
.append("\n");
|
||
|
Logger.error("修复供应商数据失败: " + supplierNumber, e);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// 构建最终消息
|
||
|
StringBuilder finalMessage = new StringBuilder();
|
||
|
finalMessage.append("处理完成!\n")
|
||
|
.append("成功处理: ").append(successCount).append("条\n")
|
||
|
.append("跳过处理: ").append(skipCount).append("条\n")
|
||
|
.append("处理失败: ").append(errorCount).append("条\n\n");
|
||
|
|
||
|
if (successCount > 0) {
|
||
|
finalMessage.append(successMessage.toString()).append("\n");
|
||
|
}
|
||
|
|
||
|
if (errorCount > 0) {
|
||
|
finalMessage.append(errorMessage.toString());
|
||
|
}
|
||
|
|
||
|
this.getView().showMessage(finalMessage.toString());
|
||
|
}
|
||
|
}
|