133 lines
5.6 KiB
Java
133 lines
5.6 KiB
Java
|
|
package tqq9.lc123.cloud.app.plugin.operate.ap;
|
||
|
|
|
||
|
|
import kd.bos.algo.DataSet;
|
||
|
|
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.db.DB;
|
||
|
|
import kd.bos.db.DBRoute;
|
||
|
|
import kd.bos.entity.ExtendedDataEntity;
|
||
|
|
import kd.bos.entity.operate.OperateOptionConst;
|
||
|
|
import kd.bos.entity.operate.result.OperationResult;
|
||
|
|
import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
|
||
|
|
import kd.bos.entity.plugin.AddValidatorsEventArgs;
|
||
|
|
import kd.bos.entity.plugin.PreparePropertysEventArgs;
|
||
|
|
import kd.bos.entity.validate.AbstractValidator;
|
||
|
|
import kd.bos.logging.Log;
|
||
|
|
import kd.bos.logging.LogFactory;
|
||
|
|
import kd.bos.orm.ORM;
|
||
|
|
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.operation.SaveServiceHelper;
|
||
|
|
import kd.sdk.plugin.Plugin;
|
||
|
|
import tqq9.lc123.cloud.app.plugin.operate.cas.PurOrderReversePayBillPlugin;
|
||
|
|
|
||
|
|
import java.sql.*;
|
||
|
|
import java.math.BigDecimal;
|
||
|
|
import java.sql.DriverManager;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 付款单操作插件
|
||
|
|
*/
|
||
|
|
public class PayBillOperationPlugin extends AbstractOperationServicePlugIn implements Plugin {
|
||
|
|
private final static Log logger = LogFactory.getLog(PayBillOperationPlugin.class);
|
||
|
|
|
||
|
|
private static String URL;
|
||
|
|
private static String USERNAME;
|
||
|
|
private static String PASSWORD;
|
||
|
|
|
||
|
|
static {
|
||
|
|
DynamicObject url = BusinessDataServiceHelper.loadSingle("tqq9_thirdconfig", "name",
|
||
|
|
new QFilter[]{new QFilter("number", QCP.equals, "EqmDatabase_url")});
|
||
|
|
URL = url != null ? url.getString("name") : null;
|
||
|
|
DynamicObject userName = BusinessDataServiceHelper.loadSingle("tqq9_thirdconfig", "name",
|
||
|
|
new QFilter[]{new QFilter("number", QCP.equals, "EqmDatabase_username")});
|
||
|
|
USERNAME = userName != null ? userName.getString("name") : null;
|
||
|
|
DynamicObject passWord = BusinessDataServiceHelper.loadSingle("tqq9_thirdconfig", "name",
|
||
|
|
new QFilter[]{new QFilter("number", QCP.equals, "EqmDatabase_password")});
|
||
|
|
PASSWORD = passWord != null ? passWord.getString("name") : null;
|
||
|
|
}
|
||
|
|
|
||
|
|
@Override
|
||
|
|
public void onPreparePropertys(PreparePropertysEventArgs e) {
|
||
|
|
super.onPreparePropertys(e);
|
||
|
|
e.getFieldKeys().add("entry.e_payableamt");
|
||
|
|
e.getFieldKeys().add("tqq9_banktxn");
|
||
|
|
}
|
||
|
|
|
||
|
|
@Override
|
||
|
|
public void onAddValidators(AddValidatorsEventArgs e) {
|
||
|
|
super.onAddValidators(e);
|
||
|
|
e.addValidator(new PayBillOperationPlugin.BankTxnValidator());
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 付款退款校验流水号是否存在
|
||
|
|
*/
|
||
|
|
class BankTxnValidator extends AbstractValidator {
|
||
|
|
@Override
|
||
|
|
public void validate() {
|
||
|
|
logger.info(URL);
|
||
|
|
logger.info(USERNAME);
|
||
|
|
logger.info(PASSWORD);
|
||
|
|
Connection conn = null;
|
||
|
|
Statement stmt = null;
|
||
|
|
ResultSet rs = null;
|
||
|
|
|
||
|
|
|
||
|
|
for (ExtendedDataEntity dataEntity : this.getDataEntities()) {
|
||
|
|
DynamicObject dataEntity1 = dataEntity.getDataEntity();
|
||
|
|
DynamicObjectCollection entry = dataEntity1.getDynamicObjectCollection("entry");
|
||
|
|
for (DynamicObject dynamicObject : entry) {
|
||
|
|
BigDecimal e_payableamt = dynamicObject.getBigDecimal("e_payableamt");//应付金额
|
||
|
|
if (e_payableamt.compareTo(BigDecimal.ZERO) < 0) {
|
||
|
|
String banktxn = dataEntity1.getString("tqq9_banktxn");//银行流水号
|
||
|
|
String billno = dataEntity1.getString("billno");//银行流水号
|
||
|
|
if(StringUtils.isBlank(banktxn)){
|
||
|
|
this.addErrorMessage(dataEntity, "单据号:" + billno + ",银行流水为空,无法审核");
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
try {
|
||
|
|
Class.forName("com.mysql.cj.jdbc.Driver");
|
||
|
|
conn = DriverManager.getConnection(URL, USERNAME, PASSWORD);
|
||
|
|
// 创建Statement对象
|
||
|
|
stmt = conn.createStatement();
|
||
|
|
String sql = "/*dialect*/SELECT * FROM v_c1cm_bank_serial where bank_voucher='" + banktxn + "'";
|
||
|
|
logger.info("sql-" + sql);
|
||
|
|
|
||
|
|
rs = stmt.executeQuery(sql);
|
||
|
|
|
||
|
|
if (!rs.next()) {
|
||
|
|
this.addErrorMessage(dataEntity, "单据号:" + billno + ",银行流水:" + banktxn + ",在E企明系统中不存在,无法审核");
|
||
|
|
}
|
||
|
|
break;
|
||
|
|
} catch (SQLException | ClassNotFoundException e) {
|
||
|
|
logger.info("同步oa中间表出现异常-" + e.getMessage());
|
||
|
|
e.printStackTrace();
|
||
|
|
} finally {
|
||
|
|
// 关闭资源
|
||
|
|
try {
|
||
|
|
if (rs != null) {
|
||
|
|
rs.close();
|
||
|
|
}
|
||
|
|
if (stmt != null) {
|
||
|
|
stmt.close();
|
||
|
|
}
|
||
|
|
if (conn != null) {
|
||
|
|
conn.close();
|
||
|
|
}
|
||
|
|
} catch (Exception e) {
|
||
|
|
e.printStackTrace();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|