71 lines
3.0 KiB
Java
71 lines
3.0 KiB
Java
package tqq9.lc123.cloud.app.plugin.operate.sys;
|
||
|
||
import kd.bos.algo.DataSet;
|
||
import kd.bos.dataentity.entity.DynamicObject;
|
||
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
||
import kd.bos.db.DB;
|
||
import kd.bos.db.DBRoute;
|
||
import kd.bos.entity.ExtendedDataEntity;
|
||
import kd.bos.entity.operate.result.OperationResult;
|
||
import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
|
||
import kd.bos.entity.plugin.AddValidatorsEventArgs;
|
||
import kd.bos.entity.plugin.args.AfterOperationArgs;
|
||
import kd.bos.entity.validate.AbstractValidator;
|
||
import kd.bos.logging.Log;
|
||
import kd.bos.logging.LogFactory;
|
||
import kd.bos.orm.ORM;
|
||
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
||
import kd.bos.servicehelper.operation.SaveServiceHelper;
|
||
import kd.sdk.plugin.Plugin;
|
||
|
||
/**
|
||
* 单据操作插件
|
||
* 物料保存操作后,将是否个性字段置为false
|
||
*/
|
||
public class MaterialSaveOp extends AbstractOperationServicePlugIn implements Plugin {
|
||
private static final Log log = LogFactory.getLog(MaterialSaveOp.class);
|
||
|
||
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 + ", 在系统中存在同名数据,无法保存");
|
||
}
|
||
}
|
||
}
|
||
}
|
||
@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);
|
||
SaveServiceHelper.save(new DynamicObject[]{material});
|
||
}
|
||
}
|
||
}
|
||
} |