|
@@ -1,9 +1,23 @@
|
|
|
package fi.gl.opplugin;
|
|
|
|
|
|
import fi.gl.business.VoucherValidator;
|
|
|
+import fi.gl.task.AutoSynVoucher;
|
|
|
+import kd.bos.dataentity.entity.DynamicObject;
|
|
|
import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
|
|
|
import kd.bos.entity.plugin.AddValidatorsEventArgs;
|
|
|
+import kd.bos.entity.plugin.args.AfterOperationArgs;
|
|
|
+import kd.bos.logging.Log;
|
|
|
+import kd.bos.logging.LogFactory;
|
|
|
+import kd.bos.orm.query.QFilter;
|
|
|
+import kd.bos.servicehelper.BusinessDataServiceHelper;
|
|
|
+import kd.scm.bid.common.constant.OperationConstant;
|
|
|
import kd.sdk.plugin.Plugin;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+
|
|
|
+import java.sql.Connection;
|
|
|
+import java.sql.DriverManager;
|
|
|
+import java.sql.PreparedStatement;
|
|
|
+import java.sql.SQLException;
|
|
|
|
|
|
/**
|
|
|
* 凭证操作插件
|
|
@@ -11,10 +25,81 @@ import kd.sdk.plugin.Plugin;
|
|
|
* 主要功能:校验凭证是否日结
|
|
|
*/
|
|
|
public class VoucherOpPlugin extends AbstractOperationServicePlugIn implements Plugin {
|
|
|
-
|
|
|
+ protected static final Log log = LogFactory.getLog(VoucherOpPlugin.class);
|
|
|
@Override
|
|
|
public void onAddValidators(AddValidatorsEventArgs e) {
|
|
|
super.onAddValidators(e);
|
|
|
e.addValidator(new VoucherValidator());
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void afterExecuteOperationTransaction(AfterOperationArgs e) {
|
|
|
+ super.afterExecuteOperationTransaction(e);
|
|
|
+ String operateKey = e.getOperationKey();
|
|
|
+ if (StringUtils.equals("antipost", operateKey)) {//反过账
|
|
|
+ DynamicObject[] dateEntities = e.getDataEntities();
|
|
|
+ String billnos = "";
|
|
|
+ for (DynamicObject dateEntity : dateEntities) {
|
|
|
+ billnos = billnos + ",'" + dateEntity.getString("billno") + "'";
|
|
|
+ }
|
|
|
+
|
|
|
+ if(!"".equals(billnos)){
|
|
|
+ billnos = billnos.substring(1);
|
|
|
+ synYY(billnos);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void synYY(String billnos) {
|
|
|
+ Connection conn = null;
|
|
|
+ PreparedStatement pstmt = null;
|
|
|
+ //连接数据库
|
|
|
+ try {
|
|
|
+ conn = getConnect(); // 获取数据库连接
|
|
|
+ if(conn!=null){
|
|
|
+ String deleteSql = "DELETE jf_voucher WHERE voucherno in("+billnos+")";
|
|
|
+ log.info("[凭证反过账同步用友]执行删除sql"+deleteSql);
|
|
|
+ // 准备删除语句
|
|
|
+ pstmt = conn.prepareStatement(deleteSql);
|
|
|
+ // 执行删除操作
|
|
|
+ int affectedRows = pstmt.executeUpdate();
|
|
|
+ log.info("[凭证反过账同步用友]成功删除"+affectedRows+"条");
|
|
|
+ }
|
|
|
+ } catch (ClassNotFoundException e) {
|
|
|
+ log.info("[凭证反过账同步用友]删除失败:"+e.getMessage());
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ } catch (SQLException e) {
|
|
|
+ log.info("[凭证反过账同步用友]删除失败:"+e.getMessage());
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }finally{
|
|
|
+ try {
|
|
|
+ if(conn!=null){
|
|
|
+ conn.setAutoCommit(true); // 重新开启自动提交
|
|
|
+ conn.close();
|
|
|
+ }
|
|
|
+ if(pstmt!=null){
|
|
|
+ pstmt.close();
|
|
|
+ }
|
|
|
+ }catch (SQLException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private Connection getConnect() throws ClassNotFoundException, SQLException {
|
|
|
+ //1.获取接口链接等信息
|
|
|
+ DynamicObject jkpzxx = BusinessDataServiceHelper.loadSingle("nckd_jkpzxx",
|
|
|
+ new QFilter[]{new QFilter("number","=","synvoucher")});
|
|
|
+ String servername = jkpzxx.getString("nckd_servername");
|
|
|
+ String port = jkpzxx.getString("nckd_port");
|
|
|
+ String username = jkpzxx.getString("nckd_user");
|
|
|
+ String password = jkpzxx.getString("nckd_password");
|
|
|
+ String jdbcUrl = "jdbc:oracle:thin:@"+servername+":"+port+"/service";
|
|
|
+ // 加载Oracle JDBC驱动
|
|
|
+ Class.forName("oracle.jdbc.driver.OracleDriver");
|
|
|
+ // 建立连接
|
|
|
+ Connection conn = DriverManager.getConnection(jdbcUrl, username, password);
|
|
|
+
|
|
|
+ return conn;
|
|
|
+ }
|
|
|
}
|