199 lines
		
	
	
		
			9.5 KiB
		
	
	
	
		
			Java
		
	
	
	
			
		
		
	
	
			199 lines
		
	
	
		
			9.5 KiB
		
	
	
	
		
			Java
		
	
	
	
package tqq9.lc123.cloud.app.plugin.operate.ap;
 | 
						|
 | 
						|
import com.google.gson.Gson;
 | 
						|
import kd.bos.dataentity.entity.DynamicObject;
 | 
						|
import kd.bos.dataentity.entity.DynamicObjectCollection;
 | 
						|
import kd.bos.dataentity.utils.StringUtils;
 | 
						|
import kd.bos.entity.ExtendedDataEntity;
 | 
						|
import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
 | 
						|
import kd.bos.entity.plugin.AddValidatorsEventArgs;
 | 
						|
import kd.bos.entity.plugin.PreparePropertysEventArgs;
 | 
						|
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.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 tqq9.lc123.cloud.app.plugin.utils.HttpRequestUtils;
 | 
						|
 | 
						|
import java.io.IOException;
 | 
						|
import java.math.BigDecimal;
 | 
						|
import java.sql.*;
 | 
						|
import java.util.HashMap;
 | 
						|
 | 
						|
/**
 | 
						|
 * 付款单操作插件
 | 
						|
 */
 | 
						|
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;
 | 
						|
    private static String Use_URL;
 | 
						|
 | 
						|
 | 
						|
    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;
 | 
						|
        url = BusinessDataServiceHelper.loadSingle("tqq9_thirdconfig", "name",
 | 
						|
                new QFilter[]{new QFilter("number", QCP.equals, "FLXT_BillCreate_Url")});
 | 
						|
        Use_URL = url != null ? url.getString("name") : null;
 | 
						|
    }
 | 
						|
 | 
						|
    private final static HashMap<String, String> tokenMap = new HashMap<String, String>() {{
 | 
						|
        put("Authorization", "Bearer b96dad1eb4f84c41bae651162aeacdd3");
 | 
						|
    }};
 | 
						|
 | 
						|
 | 
						|
    @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();
 | 
						|
                            }
 | 
						|
                        }
 | 
						|
                    }
 | 
						|
                }
 | 
						|
            }
 | 
						|
 | 
						|
 | 
						|
        }
 | 
						|
    }
 | 
						|
 | 
						|
    @Override
 | 
						|
    public void afterExecuteOperationTransaction(AfterOperationArgs e) {
 | 
						|
        super.afterExecuteOperationTransaction(e);
 | 
						|
        for (DynamicObject dataEntity : e.getDataEntities()) {
 | 
						|
            String billno = dataEntity.getString("billno");
 | 
						|
            BigDecimal tqq9_hshfsyje = dataEntity.getBigDecimal("tqq9_hshfsyje");//含税货返使用金额
 | 
						|
            BigDecimal tqq9_hsxfsyje = dataEntity.getBigDecimal("tqq9_hsxfsyje");//含税现返使用金额
 | 
						|
            BigDecimal tqq9_payamount = dataEntity.getBigDecimal("tqq9_payamount");//折扣后返利后价税合计
 | 
						|
            String tqq9_hfid = dataEntity.getString("tqq9_hfid");//货返id
 | 
						|
            String tqq9_xfid = dataEntity.getString("tqq9_xfid");//现返id
 | 
						|
            if (tqq9_hshfsyje.compareTo(BigDecimal.ZERO) > 0 && tqq9_payamount.compareTo(BigDecimal.ZERO) == 0) {
 | 
						|
                DynamicObject tqq9_hshfsysl = dataEntity.getDynamicObject("tqq9_hshfsysl");//含税货返使用税率
 | 
						|
                BigDecimal taxrate = tqq9_hshfsysl.getBigDecimal("taxrate");
 | 
						|
                BigDecimal taxamount = tqq9_hshfsyje.multiply(taxrate.divide(new BigDecimal(100).add(taxrate)));//税额
 | 
						|
                HashMap<String, Object> bodyMap = new HashMap<>();
 | 
						|
                bodyMap.put("id", tqq9_hfid);
 | 
						|
                bodyMap.put("lockMoney", tqq9_hshfsyje);
 | 
						|
                bodyMap.put("lockTaxAmount", taxamount);
 | 
						|
                Gson gson = new Gson();
 | 
						|
                try {
 | 
						|
                    String bodyString = HttpRequestUtils.postJson(Use_URL, bodyMap.toString(), tokenMap);
 | 
						|
                    HashMap map = gson.fromJson(bodyString, HashMap.class);
 | 
						|
                    Boolean data = (Boolean) map.get("data");
 | 
						|
                    if (!data) {
 | 
						|
                        this.getOperationResult().setMessage("采购订单:" + billno + ",审核时扣除订单金额失败");
 | 
						|
                    } else {
 | 
						|
                        dataEntity.set("tqq9_isrebatecalculate", true);
 | 
						|
                        SaveServiceHelper.save(new DynamicObject[]{dataEntity});
 | 
						|
                    }
 | 
						|
                } catch (IOException ex) {
 | 
						|
                    throw new RuntimeException(ex);
 | 
						|
                }
 | 
						|
                //现返审核
 | 
						|
            } else if (tqq9_hsxfsyje.compareTo(BigDecimal.ZERO) > 0 && tqq9_payamount.compareTo(BigDecimal.ZERO) == 0) {
 | 
						|
                DynamicObject tqq9_hsxfsysl = dataEntity.getDynamicObject("tqq9_hsxfsysl");//含税现返使用税率
 | 
						|
                BigDecimal taxrate = tqq9_hsxfsysl.getBigDecimal("taxrate");
 | 
						|
                BigDecimal taxamount = tqq9_hsxfsyje.multiply(taxrate.divide(new BigDecimal(100).add(taxrate)));//税额
 | 
						|
                HashMap<String, Object> bodyMap = new HashMap<>();
 | 
						|
                bodyMap.put("id", tqq9_xfid);
 | 
						|
                bodyMap.put("lockMoney", tqq9_hsxfsyje);
 | 
						|
                bodyMap.put("lockTaxAmount", taxamount);
 | 
						|
                Gson gson = new Gson();
 | 
						|
                try {
 | 
						|
                    String bodyString = HttpRequestUtils.postJson(Use_URL, bodyMap.toString(), tokenMap);
 | 
						|
                    HashMap map = gson.fromJson(bodyString, HashMap.class);
 | 
						|
                    Boolean data = (Boolean) map.get("data");
 | 
						|
                    if (!data) {
 | 
						|
                        this.getOperationResult().setMessage("采购订单:" + billno + ",审核时扣除订单金额失败");
 | 
						|
                    } else {
 | 
						|
                        dataEntity.set("tqq9_isrebatecalculate", true);
 | 
						|
                        SaveServiceHelper.save(new DynamicObject[]{dataEntity});
 | 
						|
                    }
 | 
						|
                } catch (IOException ex) {
 | 
						|
                    throw new RuntimeException(ex);
 | 
						|
                }
 | 
						|
            }
 | 
						|
        }
 | 
						|
 | 
						|
 | 
						|
    }
 | 
						|
} |