2025-12-10 08:24:27 +00:00
|
|
|
|
package tqq9.lc123.cloud.app.plugin.operate.sys;
|
|
|
|
|
|
|
2025-12-12 03:18:28 +00:00
|
|
|
|
import kd.bos.algo.DataSet;
|
2025-12-10 08:24:27 +00:00
|
|
|
|
import kd.bos.dataentity.entity.DynamicObject;
|
2025-12-12 03:18:28 +00:00
|
|
|
|
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
|
|
|
|
|
import kd.bos.db.DB;
|
|
|
|
|
|
import kd.bos.db.DBRoute;
|
|
|
|
|
|
import kd.bos.entity.ExtendedDataEntity;
|
2025-12-10 08:24:27 +00:00
|
|
|
|
import kd.bos.entity.operate.result.OperationResult;
|
|
|
|
|
|
import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
|
2025-12-12 03:18:28 +00:00
|
|
|
|
import kd.bos.entity.plugin.AddValidatorsEventArgs;
|
2025-12-10 08:24:27 +00:00
|
|
|
|
import kd.bos.entity.plugin.args.AfterOperationArgs;
|
2025-12-12 03:18:28 +00:00
|
|
|
|
import kd.bos.entity.validate.AbstractValidator;
|
2025-12-10 08:24:27 +00:00
|
|
|
|
import kd.bos.logging.Log;
|
|
|
|
|
|
import kd.bos.logging.LogFactory;
|
2025-12-12 03:18:28 +00:00
|
|
|
|
import kd.bos.orm.ORM;
|
2025-12-10 08:24:27 +00:00
|
|
|
|
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
2025-12-10 09:50:15 +00:00
|
|
|
|
import kd.bos.servicehelper.operation.SaveServiceHelper;
|
2025-12-10 08:24:27 +00:00
|
|
|
|
import kd.sdk.plugin.Plugin;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 单据操作插件
|
|
|
|
|
|
* 物料保存操作后,将是否个性字段置为false
|
|
|
|
|
|
*/
|
|
|
|
|
|
public class MaterialSaveOp extends AbstractOperationServicePlugIn implements Plugin {
|
|
|
|
|
|
private static final Log log = LogFactory.getLog(MaterialSaveOp.class);
|
2025-12-12 03:18:28 +00:00
|
|
|
|
|
|
|
|
|
|
public void onAddValidators(AddValidatorsEventArgs e) {
|
|
|
|
|
|
super.onAddValidators(e);
|
|
|
|
|
|
e.addValidator(new UniqueNameValidate());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
*校验器,根据物料名称(去空格)验重
|
|
|
|
|
|
*/
|
|
|
|
|
|
class UniqueNameValidate extends AbstractValidator {
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void validate() {
|
|
|
|
|
|
for (ExtendedDataEntity dataEntity : this.getDataEntities()) {
|
|
|
|
|
|
String name = dataEntity.getDataEntity().getString("name");//物料名称
|
|
|
|
|
|
String id = dataEntity.getDataEntity().getString("id");//id
|
|
|
|
|
|
String sql = "/*dialect*/ SELECT REPLACE(fname, ' ', '') AS name\n" +
|
|
|
|
|
|
"FROM T_BD_Material\n" +
|
|
|
|
|
|
"WHERE REPLACE(fname, ' ', '') = REPLACE('" + name + "', ' ', '')";
|
|
|
|
|
|
if (id != null && !id.isEmpty()&& !"0".equals(id)) {
|
|
|
|
|
|
sql += " AND fid <> " + id;
|
|
|
|
|
|
}
|
|
|
|
|
|
DataSet materialDataSet = DB.queryDataSet(this.getClass().getName(), DBRoute.of("sys"), sql);
|
|
|
|
|
|
DataSet copy1 = materialDataSet.copy();
|
|
|
|
|
|
DynamicObjectCollection dynamicObjects = ORM.create().toPlainDynamicObjectCollection(copy1);
|
|
|
|
|
|
if (dynamicObjects.size()>0) {
|
|
|
|
|
|
|
|
|
|
|
|
this.addErrorMessage(dataEntity, "物料:" + name + ", 在系统中存在同名数据,无法保存");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-12-10 08:24:27 +00:00
|
|
|
|
@Override
|
|
|
|
|
|
public void afterExecuteOperationTransaction(AfterOperationArgs e) {
|
|
|
|
|
|
super.afterExecuteOperationTransaction(e);
|
|
|
|
|
|
OperationResult operationResult = this.getOperationResult();
|
|
|
|
|
|
if (operationResult.isSuccess()) {
|
|
|
|
|
|
DynamicObject[] dataEntities = e.getDataEntities();
|
|
|
|
|
|
for (DynamicObject material : dataEntities) {
|
|
|
|
|
|
material = BusinessDataServiceHelper.loadSingle(material.getPkValue(), material.getDynamicObjectType().getName());
|
|
|
|
|
|
material.set("tqq9_checkboxfield", false);
|
2025-12-10 09:50:15 +00:00
|
|
|
|
SaveServiceHelper.save(new DynamicObject[]{material});
|
2025-12-10 08:24:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|