106 lines
		
	
	
		
			5.5 KiB
		
	
	
	
		
			Java
		
	
	
	
		
		
			
		
	
	
			106 lines
		
	
	
		
			5.5 KiB
		
	
	
	
		
			Java
		
	
	
	
| 
								 | 
							
								package tqq9.lc123.cloud.app.api.controller;
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								import com.drew.lang.annotations.NotNull;
							 | 
						|||
| 
								 | 
							
								import kd.bos.dataentity.entity.DynamicObject;
							 | 
						|||
| 
								 | 
							
								import kd.bos.dataentity.entity.DynamicObjectCollection;
							 | 
						|||
| 
								 | 
							
								import kd.bos.dataentity.utils.StringUtils;
							 | 
						|||
| 
								 | 
							
								import kd.bos.form.plugin.AbstractFormPlugin;
							 | 
						|||
| 
								 | 
							
								import kd.bos.logging.Log;
							 | 
						|||
| 
								 | 
							
								import kd.bos.logging.LogFactory;
							 | 
						|||
| 
								 | 
							
								import kd.bos.openapi.common.custom.annotation.ApiController;
							 | 
						|||
| 
								 | 
							
								import kd.bos.openapi.common.custom.annotation.ApiParam;
							 | 
						|||
| 
								 | 
							
								import kd.bos.openapi.common.custom.annotation.ApiPostMapping;
							 | 
						|||
| 
								 | 
							
								import kd.bos.openapi.common.result.CustomApiResult;
							 | 
						|||
| 
								 | 
							
								import kd.bos.orm.query.QCP;
							 | 
						|||
| 
								 | 
							
								import kd.bos.orm.query.QFilter;
							 | 
						|||
| 
								 | 
							
								import kd.bos.servicehelper.BusinessDataServiceHelper;
							 | 
						|||
| 
								 | 
							
								import kd.bos.servicehelper.botp.BFTrackerServiceHelper;
							 | 
						|||
| 
								 | 
							
								import kd.sdk.plugin.Plugin;
							 | 
						|||
| 
								 | 
							
								import tqq9.lc123.cloud.app.api.model.WMSInvoiceQueryModel;
							 | 
						|||
| 
								 | 
							
								import tqq9.lc123.cloud.app.api.utils.Constants;
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								import java.util.*;
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								/**
							 | 
						|||
| 
								 | 
							
								 * WMS发票接口
							 | 
						|||
| 
								 | 
							
								 */
							 | 
						|||
| 
								 | 
							
								@ApiController(value = "WMSInvoiceQueryController", desc = "WMS发票查询接口,自定义插件")
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								public class WMSInvoiceQueryController extends AbstractFormPlugin implements Plugin {
							 | 
						|||
| 
								 | 
							
								    private final static Log logger = LogFactory.getLog(WMSInvoiceQueryController.class);
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								    @ApiPostMapping(value = "/WMS_InvoiceQuery", desc = "WMS发票查询api接口")
							 | 
						|||
| 
								 | 
							
								    public CustomApiResult<WMSInvoiceQueryModel> WMS_InvoiceQuery
							 | 
						|||
| 
								 | 
							
								            (@NotNull @ApiParam(value = "入参", example = "") HashMap<String, Object> data) {
							 | 
						|||
| 
								 | 
							
								        WMSInvoiceQueryModel wmsInvoiceQueryModel = new WMSInvoiceQueryModel();
							 | 
						|||
| 
								 | 
							
								        List<WMSInvoiceQueryModel.ResultBean> result =  new ArrayList<>();
							 | 
						|||
| 
								 | 
							
								        WMSInvoiceQueryModel.ResultBean resultBean = new WMSInvoiceQueryModel.ResultBean();
							 | 
						|||
| 
								 | 
							
								        String billno = data.get("cDPCode").toString();//发货通知单编号
							 | 
						|||
| 
								 | 
							
								        String fileurl = null;
							 | 
						|||
| 
								 | 
							
								        QFilter qFilter = new QFilter("billno", QCP.in, billno);
							 | 
						|||
| 
								 | 
							
								        qFilter.and("billstatus", QCP.equals, "C");
							 | 
						|||
| 
								 | 
							
								        DynamicObject sm_delivernotice = BusinessDataServiceHelper.loadSingle(Constants.SM_DELIVERNOTICE, qFilter.toArray());
							 | 
						|||
| 
								 | 
							
								        if (sm_delivernotice != null) {
							 | 
						|||
| 
								 | 
							
								//            String mainbillnumber = sm_delivernotice.getString("mainbillnumber");//核心单据编号
							 | 
						|||
| 
								 | 
							
								            DynamicObjectCollection billentry = sm_delivernotice.getDynamicObjectCollection("billentry");//物料分录
							 | 
						|||
| 
								 | 
							
								            String mainbillnumber = billentry.get(0).getString("mainbillnumber");//核心单据编号
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								            DynamicObject sm_salorder = BusinessDataServiceHelper.loadSingle(Constants.SM_SALORDER, new QFilter[]{new QFilter("billno", QCP.equals, mainbillnumber).and("billentry.hasarbusbill", QCP.equals, true)});
							 | 
						|||
| 
								 | 
							
								            if (sm_salorder != null) {
							 | 
						|||
| 
								 | 
							
								                DynamicObject sim_original_bil = BusinessDataServiceHelper.loadSingle(Constants.SIM_ORIGINAL_BILL, new QFilter[]{new QFilter("sim_original_bill_item.corebillno", QCP.equals, mainbillnumber)});
							 | 
						|||
| 
								 | 
							
								                if (sim_original_bil != null) {
							 | 
						|||
| 
								 | 
							
								                    String invoiceno = sim_original_bil.getString("invoiceno");
							 | 
						|||
| 
								 | 
							
								                    DynamicObject sim_vatinvoice = BusinessDataServiceHelper.loadSingle("sim_vatinvoice", new QFilter[]{new QFilter("invoiceno", QCP.equals, invoiceno)});
							 | 
						|||
| 
								 | 
							
								                    if (sim_vatinvoice != null && StringUtils.isNotBlank(sim_vatinvoice.getString("fileurl"))) {
							 | 
						|||
| 
								 | 
							
								                        fileurl = sim_vatinvoice.getString("fileurl");
							 | 
						|||
| 
								 | 
							
								                    }
							 | 
						|||
| 
								 | 
							
								                }
							 | 
						|||
| 
								 | 
							
								            }
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								        resultBean.setInvoiceUrl(fileurl);
							 | 
						|||
| 
								 | 
							
								        result.add(resultBean);
							 | 
						|||
| 
								 | 
							
								        wmsInvoiceQueryModel.setResult(result);
							 | 
						|||
| 
								 | 
							
								        return CustomApiResult.success(wmsInvoiceQueryModel);
							 | 
						|||
| 
								 | 
							
								    }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								    /**
							 | 
						|||
| 
								 | 
							
								     * 下查寻找对应类型的所有单据
							 | 
						|||
| 
								 | 
							
								     *
							 | 
						|||
| 
								 | 
							
								     * @param targetLabel
							 | 
						|||
| 
								 | 
							
								     * @param targetId
							 | 
						|||
| 
								 | 
							
								     * @return
							 | 
						|||
| 
								 | 
							
								     */
							 | 
						|||
| 
								 | 
							
								    private HashSet<Long> getDocumentsByType(String targetLabel, Long targetId) {
							 | 
						|||
| 
								 | 
							
								        Map<String, HashSet<Long>> srcBills = BFTrackerServiceHelper.findTargetBills(targetLabel, new Long[]{targetId});
							 | 
						|||
| 
								 | 
							
								        Map<String, HashSet<Long>> nextSrcBills = new HashMap<>();
							 | 
						|||
| 
								 | 
							
								        HashSet<Long> returnids = new HashSet<>();
							 | 
						|||
| 
								 | 
							
								        if (srcBills == null && srcBills.isEmpty()) {
							 | 
						|||
| 
								 | 
							
								            return null;
							 | 
						|||
| 
								 | 
							
								        } else {
							 | 
						|||
| 
								 | 
							
								            do {
							 | 
						|||
| 
								 | 
							
								                for (Map.Entry<String, HashSet<Long>> entry : srcBills.entrySet()) {
							 | 
						|||
| 
								 | 
							
								                    String srcLabel = entry.getKey();  // 获取下单据标识
							 | 
						|||
| 
								 | 
							
								                    HashSet<Long> srcIds = entry.getValue();  // 获取下游单据ID
							 | 
						|||
| 
								 | 
							
								                    if (StringUtils.equals(srcLabel, "sim_original_bill")) {
							 | 
						|||
| 
								 | 
							
								                        returnids.addAll(srcIds);
							 | 
						|||
| 
								 | 
							
								                    } else {
							 | 
						|||
| 
								 | 
							
								                        Map<String, HashSet<Long>> newSrcBills = BFTrackerServiceHelper.findTargetBills(targetLabel, srcIds.toArray(new Long[srcIds.size()]));
							 | 
						|||
| 
								 | 
							
								                        for (Map.Entry<String, HashSet<Long>> newEntry : newSrcBills.entrySet()) {
							 | 
						|||
| 
								 | 
							
								                            // 如果 nextSrcBills 中已经存在相同的 key,使用 addAll 合并集合
							 | 
						|||
| 
								 | 
							
								                            if (nextSrcBills.containsKey(newEntry.getKey())) {
							 | 
						|||
| 
								 | 
							
								                                nextSrcBills.get(newEntry.getKey()).addAll(entry.getValue());
							 | 
						|||
| 
								 | 
							
								                            } else {
							 | 
						|||
| 
								 | 
							
								                                // 如果 nextSrcBills 中不存在该 key,直接添加
							 | 
						|||
| 
								 | 
							
								                                nextSrcBills.put(entry.getKey(), new HashSet<>(entry.getValue()));
							 | 
						|||
| 
								 | 
							
								                            }
							 | 
						|||
| 
								 | 
							
								                        }
							 | 
						|||
| 
								 | 
							
								                        srcBills = nextSrcBills;
							 | 
						|||
| 
								 | 
							
								                        nextSrcBills.clear();
							 | 
						|||
| 
								 | 
							
								                    }
							 | 
						|||
| 
								 | 
							
								                }
							 | 
						|||
| 
								 | 
							
								            } while (srcBills.isEmpty());
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								        return returnids;
							 | 
						|||
| 
								 | 
							
								    }
							 | 
						|||
| 
								 | 
							
								}
							 |