Sp_Sis_GetMaxNo.md 2.49 KB

Sp_Sis_GetMaxNo (procedure)

最大单据号

  • Type: PROCEDURE
  • Deterministic: NO
  • SQL data access: CONTAINS SQL

Parameters

# Mode Name Type
1 IN sBillType varchar(100)
2 OUT sReturn varchar(100)
3 IN sFormGuid varchar(100)
4 IN sSaleManGuid varchar(100)
5 IN sCustomerGuid varchar(100)
6 IN sClassNo longtext
7 IN sBrId varchar(100)
8 IN sSuId varchar(100)

Body

Body is not pre-cached. To inspect: mysql --defaults-file=~/.my.cnf -e 'SHOW CREATE PROCEDURESpSis_GetMaxNo'._

Narrative

Business context: 系统工具 — 单据号 (bill-number) generator. Universal next-bill-number factory used during bill-master save: returns the next sequential sBillNo for a given target table (mftworkordermaster, mftproductmaster, pitproductinstoremaster, sales/purchase masters, …) using the per-form template configured in SysBillNoSettings (sBillNoTitle, sBillNoType, iBillNoLength, sColumnNames, sReset).

What it does: Reads SysBillNoSettings for sFormId=sFormGuid (with sSrcFormId redirection) to learn the title prefix, the type code (nyrlsh/nylsh/nlsh/ywybhnylsh/khbhlsh/khjclsh/yjhlsh/…) and the numeric width. Builds the time/sales-man/customer/product prefix accordingly — sYear/sMonth/sDay/sMinute from NOW(), EleEmployee.sEmployeeNo for the salesman, EleCustomer.sCustomerShort/sCustomerNo for the customer, EleProduct.sProductNo for the product. Then queries MAX(CAST(RIGHT(sBillNo, iBillNoLength) AS UNSIGNED)) from the target table filtered by the same prefix + reset window, adds 1, left-pads to iBillNoLength, and returns prefix || sequence in sReturn. Also routes through Fn_json_extract to read fields out of the sClassNo JSON blob for product/material-classify suffixes.

Invocation: Called via procedureService.getCallProByMap(...) from Java BusinessCharacterFormatServiceImpl.getMaxBillNo(...) (the standard pipeline) and webService.service.impl.ErpOrderProcurementServiceImpl.getMaxBillNo(...) (web-service variant for external order intake). Also invoked from peer routines Sp_Calc_sOis, Sp_Calc_sWod, Sp_Manufacture_InsertMftPlanBook, Sp_Manufacture_InsertMftPlanToErp, and the split procs Sp_Split_sMpt / Sp_Split_sWod when they fabricate new master rows. Install scripts: script/标版/30100101/Sp_Sis_GetMaxNo.sql plus the optimize/ patch variant.