134 lines
		
	
	
		
			7.1 KiB
		
	
	
	
		
			Java
		
	
	
	
			
		
		
	
	
			134 lines
		
	
	
		
			7.1 KiB
		
	
	
	
		
			Java
		
	
	
	
| package tqq9.lc123.cloud.app.plugin.operate.pm;
 | |
| 
 | |
| import com.google.gson.Gson;
 | |
| import kd.bos.dataentity.entity.DynamicObject;
 | |
| import kd.bos.dataentity.utils.StringUtils;
 | |
| import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
 | |
| import kd.bos.entity.plugin.args.AfterOperationArgs;
 | |
| 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.sdk.plugin.Plugin;
 | |
| import tqq9.lc123.cloud.app.plugin.utils.HttpRequestUtils;
 | |
| 
 | |
| import java.io.IOException;
 | |
| import java.math.BigDecimal;
 | |
| import java.util.HashMap;
 | |
| 
 | |
| /**
 | |
|  * 单据操作插件
 | |
|  */
 | |
| public class PurOrderBillRebatePlugin extends AbstractOperationServicePlugIn implements Plugin {
 | |
| 
 | |
|     private final static Log logger = LogFactory.getLog(PurOrderBillRebatePlugin.class);
 | |
|     private final static String ENTRYENTITY = "billentry";
 | |
| 
 | |
|     private final static HashMap<String, String> tokenMap = new HashMap<String, String>() {{
 | |
|         put("Authorization", "Bearer b96dad1eb4f84c41bae651162aeacdd3");
 | |
|     }};
 | |
| 
 | |
|     private static String URL;
 | |
|     static {
 | |
|         DynamicObject url = BusinessDataServiceHelper.loadSingle("tqq9_thirdconfig", "name",
 | |
|                 new QFilter[]{new QFilter("number", QCP.equals, "FLXT_Balance_Url")});
 | |
|         URL = url != null ? url.getString("name") : null;
 | |
|     }
 | |
|     @Override
 | |
|     public void afterExecuteOperationTransaction(AfterOperationArgs e) {
 | |
|         super.afterExecuteOperationTransaction(e);
 | |
|         String operationKey = e.getOperationKey();
 | |
|         if (StringUtils.equals("save",operationKey)) {
 | |
|             for (DynamicObject dataEntity : e.getDataEntities()) {
 | |
|                 DynamicObject supplier = dataEntity.getDynamicObject("supplier");//供应商
 | |
|                 DynamicObject org = dataEntity.getDynamicObject("org");//组织
 | |
|                 BigDecimal tqq9_hshfsyje = dataEntity.getBigDecimal("tqq9_hshfsyje");//含税货返使用金额
 | |
|                 BigDecimal tqq9_hsxfsyje = dataEntity.getBigDecimal("tqq9_hsxfsyje");//含税现返使用金额
 | |
|                 if(tqq9_hshfsyje.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("supplierId",supplier.getString("number"));
 | |
|                     bodyMap.put("companyId",org.getString("number"));
 | |
|                     bodyMap.put("type",0);
 | |
|                     bodyMap.put("money",tqq9_hshfsyje);
 | |
|                     bodyMap.put("taxAmount",taxamount);
 | |
|                     Gson gson = new Gson();
 | |
|                     try {
 | |
|                         String bodyString = HttpRequestUtils.postJson(URL, bodyMap.toString(), tokenMap);
 | |
|                         HashMap map = gson.fromJson(bodyString, HashMap.class);
 | |
|                     } catch (IOException ex) {
 | |
|                         throw new RuntimeException(ex);
 | |
|                     }
 | |
|                 }else if(tqq9_hsxfsyje.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("supplierId",supplier.getString("number"));
 | |
|                     bodyMap.put("companyId",org.getString("number"));
 | |
|                     bodyMap.put("type",1);
 | |
|                     bodyMap.put("money",tqq9_hsxfsyje);
 | |
|                     bodyMap.put("taxAmount",taxamount);
 | |
|                     Gson gson = new Gson();
 | |
|                     try {
 | |
|                         String bodyString = HttpRequestUtils.postJson(URL, bodyMap.toString(), tokenMap);
 | |
|                         HashMap map = gson.fromJson(bodyString, HashMap.class);
 | |
|                     } catch (IOException ex) {
 | |
|                         throw new RuntimeException(ex);
 | |
|                     }
 | |
|                 }
 | |
| 
 | |
| 
 | |
|             }
 | |
| 
 | |
|         }else if(StringUtils.equals("delete",operationKey)){
 | |
|             for (DynamicObject dataEntity : e.getDataEntities()) {
 | |
|                 DynamicObject supplier = dataEntity.getDynamicObject("supplier");//供应商
 | |
|                 DynamicObject org = dataEntity.getDynamicObject("org");//组织
 | |
|                 BigDecimal tqq9_hshfsyje = dataEntity.getBigDecimal("tqq9_hshfsyje");//含税货返使用金额
 | |
|                 BigDecimal tqq9_hsxfsyje = dataEntity.getBigDecimal("tqq9_hsxfsyje");//含税现返使用金额
 | |
|                 if(tqq9_hshfsyje.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("supplierId",supplier.getString("number"));
 | |
|                     bodyMap.put("companyId",org.getString("number"));
 | |
|                     bodyMap.put("type",0);
 | |
|                     bodyMap.put("money",tqq9_hshfsyje);
 | |
|                     bodyMap.put("taxAmount",taxamount);
 | |
|                     Gson gson = new Gson();
 | |
|                     try {
 | |
|                         String bodyString = HttpRequestUtils.postJson(URL, bodyMap.toString(), tokenMap);
 | |
|                         HashMap map = gson.fromJson(bodyString, HashMap.class);
 | |
|                     } catch (IOException ex) {
 | |
|                         throw new RuntimeException(ex);
 | |
|                     }
 | |
|                 }else if(tqq9_hsxfsyje.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("supplierId",supplier.getString("number"));
 | |
|                     bodyMap.put("companyId",org.getString("number"));
 | |
|                     bodyMap.put("type",1);
 | |
|                     bodyMap.put("money",tqq9_hsxfsyje);
 | |
|                     bodyMap.put("taxAmount",taxamount);
 | |
|                     Gson gson = new Gson();
 | |
|                     try {
 | |
|                         String bodyString = HttpRequestUtils.postJson(URL, bodyMap.toString(), tokenMap);
 | |
|                         HashMap map = gson.fromJson(bodyString, HashMap.class);
 | |
|                     } catch (IOException ex) {
 | |
|                         throw new RuntimeException(ex);
 | |
|                     }
 | |
|                 }
 | |
| 
 | |
| 
 | |
|             }
 | |
| 
 | |
|         }
 | |
|     }
 | |
| } |