function getPagedList(contractId) { var contractId = body.param.contractId; var sql = ` SELECT a.id, a.contract_id contractId, a.product_id productId, a.purchase_num purchaseNum, a.purchase_price purchasePrice, a.remark, b.product_name productName, b.spec_code specCode, c.type_name typeName, d.unitcode unitCode FROM mes214820519.wms_pur_list_214820519 a, mes214820519.wms_product_214820519 b, mes214820519.wms_product_class_214820519 c, mes214820519.wms_unit_code_214820519 d WHERE a.product_id=b.id AND b.product_class_id = c.id AND b.unit_code_id=d.id AND a.contract_id=#{contractId}`; return db.pager(sql, {contractId: contractId}) } 用JavaScript语言修改这段代码
时间: 2023-07-15 11:11:37 浏览: 224
function getPagedList(contractId) {
var sql = `SELECT
a.id,
a.contract_id as contractId,
a.product_id as productId,
a.purchase_num as purchaseNum,
a.purchase_price as purchasePrice,
a.remark,
b.product_name as productName,
b.spec_code as specCode,
c.type_name as typeName,
d.unitcode as unitCode
FROM
mes214820519.wms_pur_list_214820519 a
INNER JOIN mes214820519.wms_product_214820519 b
ON a.product_id = b.id
INNER JOIN mes214820519.wms_product_class_214820519 c
ON b.product_class_id = c.id
INNER JOIN mes214820519.wms_unit_code_214820519 d
ON b.unit_code_id = d.id
WHERE
a.contract_id = :contractId`;
return db.pager(sql, { contractId: contractId });
}
在修改后的代码中,我使用了ES6模板字符串来构建SQL语句,同时使用了INNER JOIN来连接多张表,使代码更加简洁易读。另外,我还使用了命名参数代替了原来的占位符,以提高代码的可读性和可维护性。
阅读全文