feat: 新增 AdminCost 造价标准管理模块并调整手工导出未采纳清单口径

This commit is contained in:
lianjianwei2024
2026-10-29 15:54:38 +08:00
parent a90734963c
commit b79c0df557
25 changed files with 27360 additions and 58 deletions

305
AdminCost/_cos4_nodes.py Normal file
View File

@@ -0,0 +1,305 @@
"""按两份 COS4 补齐缺失的节点。
用户口径(2026-10-29):数据结构以 2 份 COS4 为准,COS4 里没有的我们不建;COS4 有的补齐。
本次新增:
项目层 系统信息 SystemInfo / 工程信息 ConstructionInfo(容器)
├ 费用精度 Option、编审信息 ProjectInfo、招标信息 TendereeInfo
├ 投标信息 BidderInfo、工程特征 AttrInfoItem、补充信息 AddiInfoItem
项目费用汇总 SummaryOfCost
建安费层 建安费费用汇总 ProjectInstallationWorkCostSummary
单位工程 其他项目 Sundry(容器) ├ 其他项目清单 SundryCosts、暂列金额 ProvisionalSums
├ 专业工程暂估价 SpecialtyProvisionalPrice
├ 计日工 DayWorkRate、总承包服务费 MainContractorAttendance
增值税 Tax、材料暂估价 ProvisionalMaterialEquipment、单位工程费用数值 SummaryOfCost
用法:python _cos4_nodes.py [--apply]
"""
import sys
import app
EN2CN = {
# 系统信息 / 费用精度
"ID1": ("编制软件信息", "String"),
"ID2": ("编制机器硬件信息", "String"),
"MakeDate1": ("文件生成时间", "Datetime"),
"MakeDate2": ("文件生成时间2", "Datetime"),
"ResPrecision": ("工料机消耗量、含量、数量类小数精度", "Integer"),
"QuantityPrecision": ("工程量、数量类小数精度", "Integer"),
"CostPrecision": ("金额、合价、费用类小数精度", "Integer"),
"RatePrecision": ("费率、指数、比率(%)类小数精度", "Integer"),
# 编审信息
"CompileCompany": ("编制单位", "String"),
"CompileDate": ("编制时间", "String"),
"Compiler": ("编制人员", "String"),
"CompilerCertNo": ("编制人员资格证书编号", "String"),
"ExamineDate": ("审核时间", "String"),
"Examiner": ("审核人", "String"),
"ExaminerCertNo": ("审核人资格证书编号", "String"),
"Approver": ("审定人", "String"),
"ApproverCertNo": ("审定人资格证书编号", "String"),
"ApproverDate": ("审定时间", "String"),
"Authorizer": ("编制单位法定代表人或其授权人", "String"),
"Contractor": ("承包单位", "String"),
"Designer": ("设计单位", "String"),
# 招标 / 投标
"TendereeName": ("招标人", "String"),
"TenderSumLimit": ("招标最高限价(元)", "Double"),
"TenderAuthorizer": ("招标单位法定代表人或其授权人", "String"),
"TenderCompiler": ("招标人编制人员", "String"),
"TenderCompilerCertNo": ("招标人编制人员资格证书编号", "String"),
"TenderCompileDate": ("招标人编制时间", "String"),
"TenderExaminer": ("招标人审核人", "String"),
"TenderExaminerCertNo": ("招标人审核人资格证书编号", "String"),
"TenderExamineDate": ("招标人审核时间", "String"),
"TenderApprover": ("招标人审定人", "String"),
"TenderApproverCertNo": ("招标人审定人资格证书编号", "String"),
"TenderApproveDate": ("招标人审定时间", "String"),
"Consultant": ("造价咨询", "String"),
"ConsultantUSCI": ("造价咨询统一社会信用代码", "String"),
"ConsultantAuthorizer": ("造价咨询法定代表人或其授权人", "String"),
"ConsultantCompiler": ("造价咨询编制人员", "String"),
"ConsultantCompilerCertNo": ("造价咨询编制人员资格证书编号", "String"),
"ConsultantCompileDate": ("造价咨询编制时间", "String"),
"ConsultantExaminer": ("造价咨询审核人", "String"),
"ConsultantExaminerCertNo": ("造价咨询审核人资格证书编号", "String"),
"ConsultantExamineDate": ("造价咨询审核时间", "String"),
"ConsultantApprover": ("造价咨询审定人", "String"),
"ConsultantApproverCertNo": ("造价咨询审定人资格证书编号", "String"),
"ConsultantApproveDate": ("造价咨询审定时间", "String"),
"Proxy": ("招标代理", "String"),
"ProxyUSCI": ("招标代理统一社会信用代码", "String"),
"ProxyAuthorizer": ("招标代理法定代表人或其授权人", "String"),
"ProxyCompiler": ("招标代理编制人员", "String"),
"ProxyCompilerCertNo": ("招标代理编制人员资格证书编号", "String"),
"ProxyCompileDate": ("招标代理编制时间", "String"),
"ProxyExaminer": ("招标代理审核人", "String"),
"ProxyExaminerCertNo": ("招标代理审核人资格证书编号", "String"),
"ProxyExamineDate": ("招标代理审核时间", "String"),
"ProxyApprover": ("招标代理审定人", "String"),
"ProxyApproverCertNo": ("招标代理审定人资格证书编号", "String"),
"ProxyApproveDate": ("招标代理审定时间", "String"),
"BidName": ("投标人", "String"),
"BidTotal": ("投标总价(元)", "Double"),
"BidAuthorizer": ("投标单位法定代表人或其授权人", "String"),
"BidCompiler": ("投标人编制人员", "String"),
"BidCompilerCertNo": ("投标人编制人员资格证书编号", "String"),
"BidCompileDate": ("投标人编制时间", "String"),
"BidExaminer": ("投标人审核人", "String"),
"BidExaminerCertNo": ("投标人审核人资格证书编号", "String"),
"BidExamineDate": ("投标人审核时间", "String"),
"BidApprover": ("投标人审定人", "String"),
"BidApproverCertNo": ("投标人审定人资格证书编号", "String"),
"BidApproveDate": ("投标人审定时间", "String"),
# 通用行属性
"Code": ("代号", "String"),
"Name": ("名称", "String"),
"Value": ("内容", "String"),
"Remark": ("备注", "String"),
"Number": ("编号", "String"),
"Unit": ("单位", "String"),
"Quantity": ("数量", "Double"),
"QtyFormula": ("计算基数", "String"),
"Rate": ("费率(%)", "Double"),
"Ratios": ("占比(%)", "Double"),
"Kind": ("类型", "Integer"),
"Total": ("合价(元)", "Double"),
"TechnicalAndEconomicIndex": ("技术经济指标", "Double"),
"CalBasis": ("计算基础", "String"),
"NoTaxTotal": ("除税合价(元)", "Double"),
"Tax": ("税金", "Double"),
# 费用汇总 26 项
"Labor": ("人工费", "Double"),
"Material": ("材料费(不含主材费)", "Double"),
"Machine": ("机械费", "Double"),
"MainMaterial": ("主材费", "Double"),
"MainMaterialEquipment": ("主材设备费", "Double"),
"Equipment": ("设备费", "Double"),
"Overhead": ("管理费", "Double"),
"Profit": ("利润", "Double"),
"DivisionalAndElementalWorks": ("分部分项工程费", "Double"),
"Preliminaries": ("措施项目费", "Double"),
"CostForHSE": ("安全文明施工措施项目费", "Double"),
"SundryCosts": ("其他项目费", "Double"),
"ProvisionalSums": ("暂列金额", "Double"),
"SpecialtyProvisionalPrice": ("专业工程暂估价", "Double"),
"DayWorkRate": ("计日工费用", "Double"),
"MainContractorAttendance": ("总承包服务费", "Double"),
"ProvisionalMaterialEquipment": ("暂估价材料", "Double"),
"LawsRegulationsAndPolicyChangeProjects": ("法律法规及政策性变化费用", "Double"),
"ChangeCost": ("变更费用", "Double"),
"ClaimForLossAndExpenses": ("索赔费用", "Double"),
"Construction": ("建筑工程费", "Double"),
"Installation": ("安装工程费", "Double"),
"ConvertedIntoRMB": ("换算人民币金额", "Double"),
"ForeignCurrency": ("外币金额", "Double"),
}
# 同名属性在不同元素里含义不同,单独覆盖
OVERRIDE = {
"SummaryOfCost": {
"Total": ("工程总价(元)", "Double"),
"Tax": ("税金/增值税销项税额", "Double"),
},
}
SUMMARY = (
"Labor Material Machine MainMaterial MainMaterialEquipment Equipment Overhead Profit"
" DivisionalAndElementalWorks Preliminaries CostForHSE SundryCosts ProvisionalSums"
" SpecialtyProvisionalPrice DayWorkRate MainContractorAttendance ProvisionalMaterialEquipment"
" LawsRegulationsAndPolicyChangeProjects ChangeCost ClaimForLossAndExpenses Construction"
" Installation Total ConvertedIntoRMB ForeignCurrency Tax"
).split()
TENDER = (
"TendereeName TenderSumLimit TenderAuthorizer TenderCompiler TenderCompilerCertNo"
" TenderCompileDate TenderExaminer TenderExaminerCertNo TenderExamineDate TenderApprover"
" TenderApproverCertNo TenderApproveDate Consultant ConsultantUSCI ConsultantAuthorizer"
" ConsultantCompiler ConsultantCompilerCertNo ConsultantCompileDate ConsultantExaminer"
" ConsultantExaminerCertNo ConsultantExamineDate ConsultantApprover ConsultantApproverCertNo"
" ConsultantApproveDate Proxy ProxyUSCI ProxyAuthorizer ProxyCompiler ProxyCompilerCertNo"
" ProxyCompileDate ProxyExaminer ProxyExaminerCertNo ProxyExamineDate ProxyApprover"
" ProxyApproverCertNo ProxyApproveDate"
).split()
BID = (
"BidName BidTotal BidAuthorizer BidCompiler BidCompilerCertNo BidCompileDate BidExaminer"
" BidExaminerCertNo BidExamineDate BidApprover BidApproverCertNo BidApproveDate"
).split()
# key -> (中文页名, 父 key, element, 属性列表)
NODES = [
("sysinfo", "系统信息", "project", "SystemInfo", "ID1 ID2 MakeDate1 MakeDate2".split()),
("coninfo", "工程信息", "project", "ConstructionInfo", []),
("option", "费用精度", "coninfo", "Option",
"ResPrecision QuantityPrecision CostPrecision RatePrecision".split()),
("projinfo", "编审信息", "coninfo", "ProjectInfo",
"CompileCompany CompileDate Compiler CompilerCertNo ExamineDate Examiner ExaminerCertNo"
" Approver ApproverCertNo ApproverDate Authorizer Contractor Designer Total".split()),
("tender", "招标信息", "coninfo", "TendereeInfo", TENDER),
("bid", "投标信息", "coninfo", "BidderInfo", BID),
("attr", "工程特征", "coninfo", "AttrInfoItem", "Code Name Value Remark".split()),
("addi", "补充信息", "coninfo", "AddiInfoItem", "Code Name Value Remark".split()),
("projcost", "项目费用汇总", "project", "SummaryOfCost", SUMMARY),
("instsum", "建安费费用汇总", "install", "ProjectInstallationWorkCostSummary",
"Code Kind Name Number Quantity Ratios Remark TechnicalAndEconomicIndex Total Unit"
" QtyFormula Rate".split()),
("sundry", "其他项目", "unit", "Sundry", []),
("sundrycost", "其他项目清单", "sundry", "SundryCosts", "Code Name Remark Total".split()),
("provsum", "暂列金额", "sundry", "ProvisionalSums", "Code Name Remark Total".split()),
("specprov", "专业工程暂估价", "sundry", "SpecialtyProvisionalPrice",
"Code Name NoTaxTotal Tax Total Remark".split()),
("daywork", "计日工", "sundry", "DayWorkRate", "Code Name Remark Total".split()),
("maincon", "总承包服务费", "sundry", "MainContractorAttendance",
"Code Name Remark Total".split()),
("tax", "增值税", "unit", "Tax", "CalBasis Code Name QtyFormula Rate Remark Total".split()),
("provmat", "材料暂估价", "unit", "ProvisionalMaterialEquipment",
"Code Name Remark Total".split()),
("unitcost", "单位工程费用数值", "unit", "SummaryOfCost", SUMMARY),
]
# 每个父节点下子节点的显示顺序(按 XML 顺序 / 造价编制习惯)
ORDER = {
"project": ["sysinfo", "coninfo", "projcost", "install"],
"coninfo": ["option", "projinfo", "tender", "bid", "attr", "addi"],
"install": ["instsum", "sectional"],
"unit": ["unitcost", "sumtab", "divlist", "divnorm", "prelist", "prenorm", "sundry",
"tax", "provmat", "lmm"],
"sundry": ["sundrycost", "provsum", "specprov", "daywork", "maincon"],
}
ROOTS = {"project": 11, "install": 13, "sectional": 14, "unit": 15,
"sumtab": 10, "divlist": 3, "divnorm": 4, "prelist": 5,
"prenorm": 6, "lmm": 2}
def main(apply=False):
app.init_db()
conn = app.connect()
try:
ids = dict(ROOTS)
made, existed = [], []
for key, name, parent_key, element, stds in NODES:
parent_id = ids.get(parent_key)
row = conn.execute("SELECT id FROM tabs WHERE name = ?", (name,)).fetchone()
if row:
conn.execute(
"UPDATE tabs SET parent_id = ?, element = ?, node_kind = 'table' WHERE id = ?",
(parent_id, element, row["id"]),
)
ids[key] = row["id"]
existed.append(name)
continue
cur = conn.execute(
"INSERT INTO tabs(name, is_fixed, sort_order, created_at, parent_id, node_kind,"
" collapsed, element) VALUES(?, 0, 0, ?, ?, 'table', 0, ?)",
(name, app.now_str(), parent_id, element),
)
ids[key] = cur.lastrowid
app.ensure_tab_columns(conn, ids[key])
made.append(name)
app.sync_field_groups(conn)
for key, name, parent_key, element, stds in NODES:
tab_id = ids[key]
gid = conn.execute(
"SELECT id FROM field_groups WHERE tab_id = ?", (tab_id,)
).fetchone()
if gid is None:
print(" !! %s 没有字段分组" % name)
continue
gid = gid["id"]
order = 3
added = 0
for std in stds:
order += 1
if std not in EN2CN:
print(" !! 缺中文名:%s" % std)
continue
cn, typ = OVERRIDE.get(element, {}).get(std) or EN2CN[std]
if conn.execute(
"SELECT id FROM columns WHERE tab_id = ? AND std_name = ?", (tab_id, std)
).fetchone():
continue
if conn.execute(
"SELECT id FROM fields WHERE group_id = ? AND name = ?", (gid, cn)
).fetchone() is None:
conn.execute(
"INSERT INTO fields(name, note, is_value, sort_order, created_at, group_id)"
" VALUES(?,?,0,?,?,?)",
(cn, "COS4 属性 %s" % std, order, app.now_str(), gid),
)
conn.execute(
"INSERT INTO columns(tab_id, name, kind, sort_order, width, created_at,"
" std_name, std_type, required, std_note) VALUES(?,?,?,?,0,?,?,?,0,?)",
(tab_id, cn, "custom", order, app.now_str(), std, typ, "COS4 属性 %s" % std),
)
added += 1
if stds:
print("[%-14s] %-44s 补 %2d 列" % (name, element, added))
# 统一排子节点顺序
for parent_key, keys in ORDER.items():
pid = ids.get(parent_key)
if pid is None:
continue
for i, k in enumerate(keys):
if k in ids:
conn.execute("UPDATE tabs SET sort_order = ? WHERE id = ?", (i + 1, ids[k]))
app.sync_field_groups(conn)
print("\n新建 %d 个节点:%s" % (len(made), "、".join(made) or "无"))
print("已存在 %d 个:%s" % (len(existed), "、".join(existed) or "无"))
if apply:
conn.commit()
print("已提交")
else:
conn.rollback()
print("预演结束(未提交)")
finally:
conn.close()
if __name__ == "__main__":
main(apply="--apply" in sys.argv)

243
AdminCost/_cos4_schema.py Normal file
View File

@@ -0,0 +1,243 @@
"""按两份 COS4 的实际属性名重建四个层级节点的属性列。
口径(用户 2026-10-29 定):
数据结构以 2 份 COS4 为准,结合标准规范;COS4 里没有的属性,我们也不建。
因此:
- 计价类别用 ValuationModel(COS4 实际写法;国标征求意见稿写作 ValuationMethod)
- 建设规模单位拆成 ScaleName(规模名称)+ Unit(单位),不再用国标的 ScaleUnit
- 删掉材料价格时间 MaterialPriceDate(两份 COS4 都没有)
- 单项工程不建专业类别 Specialty(SectionalWorks 无此属性;UnitWorks 才有)
用法:
python _cos4_schema.py 预演(不提交)
python _cos4_schema.py --apply 落库
"""
import sys
import app
# 层号 -> (元素名, [(英文属性, 中文列名, 类型, 必填, 说明)])
LAYERS = {
11: (
"ConstructionProject",
[
("Number", "项目编号", "String", 1, "建设项目的唯一编号"),
("Name", "项目名称", "String", 1, "建设项目名称"),
("FileKind", "文件类型", "Integer", 1, "1投资估算/2设计概算/3施工图预算/4工程量清单/5最高投标限价/6投标报价/7签约合同价/8结算价"),
("ValuationModel", "计价类别", "Integer", 1, "1清单计价/2定额计价/3全费用清单计价"),
("TaxModel", "计税模式", "Integer", 1, "1一般计税法/2简易计税法/3营业税计税法"),
("ProjectCategory", "项目分类", "String", 0, "项目所属分类"),
("ProjectType", "工程类型", "String", 0, "如 房屋建筑/道路工程"),
("ConstructionType", "建设性质", "Integer", 0, "1新建/2扩建/3改建/9其他"),
("AreaKind", "面积类型", "Integer", 0, "建筑面积的统计口径"),
("ProjectArea", "项目地区", "String", 0, "如 珠海市"),
("ProjectSite", "建设地点", "String", 0, "具体建设地点"),
("BulidUnit", "建设单位", "String", 0, "建设单位名称"),
("BulidAuthorizer", "建设单位法定代表人", "String", 0, "建设单位法定代表人或其授权人"),
("StandardName", "数据交换标准名称", "String", 1, "如 建设工程政府投资项目造价数据标准"),
("StandardNumber", "数据交换标准编号", "String", 1, "如 DBJ/T 15-145-2025"),
("StandardVersion", "数据交换标准版本", "String", 0, "如 4.00"),
("Scale", "建设规模", "Double", 1, "只填数字部分,如 20000"),
("ScaleName", "建设规模名称", "String", 0, "规模的文字描述"),
("Unit", "单位", "String", 1, "如 m2、km"),
("RangeOfCompilation", "编制范围", "String", 0, "本次编制包含的范围"),
("TechnicalAndEconomicIndex", "技术经济指标", "Double", 0, "单位规模对应的造价指标"),
("Explains", "总说明", "String", 0, "项目总说明"),
],
),
13: (
"ProjectInstallationWorkCost",
[
("Number", "工程编号", "String", 0, "建筑安装工程费编号"),
("Name", "工程名称", "String", 1, "建筑安装工程费名称"),
("Code", "费用代号", "String", 0, "费用代号"),
("Total", "金额(元)", "Double", 0, "金额,单位元"),
("Scale", "建设规模", "Double", 0, "只填数字部分"),
("ScaleName", "建设规模名称", "String", 0, "规模的文字描述"),
("Unit", "单位", "String", 0, "如 m2、km"),
("Ratios", "占整个项目费用比率(%)", "Double", 0, "占整个项目费用的比率"),
("TechnicalAndEconomicIndex", "技术经济指标", "Double", 0, "单位规模对应的造价指标"),
("ConvertedIntoRMB", "换算人民币金额", "Double", 0, "外币折算为人民币后的金额"),
("ForeignCurrency", "外币金额", "Double", 0, "以外币计的金额"),
("Remark", "备注", "String", 0, "备注"),
],
),
14: (
"SectionalWorks",
[
("Number", "工程编号", "String", 0, "单项工程编号"),
("Name", "工程名称", "String", 1, "单项工程名称"),
("Segment", "标段名称", "String", 0, "所属标段"),
("Code", "费用代号", "String", 0, "费用代号"),
("Total", "金额(元)", "Double", 0, "金额,单位元"),
("Ratios", "占整个项目费用比率(%)", "Double", 0, "占整个项目费用的比率"),
("Scale", "建设规模", "Double", 0, "只填数字部分"),
("ScaleName", "建设规模名称", "String", 0, "规模的文字描述"),
("Unit", "单位", "String", 0, "如 m2、km"),
("ProjectCategory", "项目分类", "String", 0, "项目所属分类"),
("ProjectType", "工程类型", "String", 0, "如 房屋建筑/道路工程"),
("ConstructionType", "建设性质", "Integer", 0, "1新建/2扩建/3改建/9其他"),
("AreaKind", "面积类型", "Integer", 0, "建筑面积的统计口径"),
("ProjectArea", "项目地区", "String", 0, "如 珠海市"),
("ProjectSite", "建设地点", "String", 0, "具体建设地点"),
("BulidUnit", "建设单位", "String", 0, "建设单位名称"),
("BulidAuthorizer", "建设单位法定代表人", "String", 0, "建设单位法定代表人或其授权人"),
("FileKind", "文件类型", "Integer", 0, "1投资估算/2设计概算/3施工图预算/4工程量清单/5最高投标限价/6投标报价/7签约合同价/8结算价"),
("ValuationModel", "计价类别", "Integer", 0, "1清单计价/2定额计价/3全费用清单计价"),
("TaxModel", "计税模式", "Integer", 0, "1一般计税法/2简易计税法/3营业税计税法"),
("StandardName", "数据交换标准名称", "String", 0, "数据交换标准名称"),
("StandardNumber", "数据交换标准编号", "String", 0, "数据交换标准编号"),
("StandardVersion", "数据交换标准版本", "String", 0, "如 4.00"),
("RangeOfCompilation", "编制范围", "String", 0, "本次编制包含的范围"),
("TechnicalAndEconomicIndex", "技术经济指标", "Double", 0, "单位规模对应的造价指标"),
("Remark", "备注", "String", 0, "备注"),
],
),
15: (
"UnitWorks",
[
("Number", "工程编号", "String", 1, "单位工程编号"),
("Name", "工程名称", "String", 1, "单位工程名称"),
("Segment", "标段名称", "String", 0, "所属标段"),
("Code", "费用代号", "String", 0, "费用代号"),
("Total", "金额(元)", "Double", 0, "金额,单位元"),
("Ratios", "占整个项目费用比率(%)", "Double", 0, "占整个项目费用的比率"),
("Specialty", "专业类别", "String", 1, "如 01 房屋建筑与装饰工程"),
("Purposes", "工程用途", "String", 0, "工程用途"),
("ValuationModel", "计价类别", "Integer", 0, "1清单计价/2定额计价/3全费用清单计价"),
("TaxModel", "计税模式", "Integer", 0, "1一般计税法/2简易计税法/3营业税计税法"),
("Scale", "建设规模", "Double", 0, "只填数字部分"),
("ScaleName", "建设规模名称", "String", 0, "规模的文字描述"),
("Unit", "单位", "String", 0, "如 m2、km"),
("ProjectCategory", "项目分类", "String", 0, "项目所属分类"),
("ProjectType", "工程类型", "String", 0, "如 房屋建筑/道路工程"),
("AreaKind", "面积类型", "Integer", 0, "建筑面积的统计口径"),
("RangeOfCompilation", "编制范围", "String", 0, "本次编制包含的范围"),
("TechnicalAndEconomicIndex", "技术经济指标", "Double", 0, "单位规模对应的造价指标"),
("BillDataBase", "清单库", "String", 0, "所用清单库"),
("NormDataBase", "定额库", "String", 0, "所用定额库"),
("QuantityCalculationRules", "工程量计算规则", "String", 0, "所用工程量计算规则"),
("AppliedRateFile", "适用费率文件", "String", 0, "所用费率文件"),
("ResInfoPricingFile", "资源信息价文件", "String", 0, "所用资源信息价文件"),
("FileName", "文件名称", "String", 0, "单位工程对应的数据文件"),
("Explains", "总说明", "String", 0, "单位工程总说明"),
("WorkContent", "工作内容", "String", 0, "工作内容说明"),
("Remark", "备注", "String", 0, "备注"),
],
),
}
# 旧属性名 -> COS4 实际属性名(国标征求意见稿与地标的写法差异)
ALIAS = {"ValuationMethod": "ValuationModel", "ScaleUnit": "Unit"}
FIXED_KINDS = ("index", "suffix", "action", "anchorline", "anchor")
def main(apply=False):
app.init_db()
conn = app.connect()
try:
for tab_id, (element, items) in LAYERS.items():
tab = conn.execute("SELECT id, name FROM tabs WHERE id = ?", (tab_id,)).fetchone()
if tab is None:
print("跳过:标签 %s 不存在" % tab_id)
continue
conn.execute("UPDATE tabs SET element = ? WHERE id = ?", (element, tab_id))
gid_row = conn.execute(
"SELECT id FROM field_groups WHERE tab_id = ?", (tab_id,)
).fetchone()
if gid_row is None:
print("跳过:%s 没有字段分组" % tab["name"])
continue
gid = gid_row["id"]
old = list(
conn.execute(
"SELECT id, name, kind, std_name, sort_order FROM columns"
" WHERE tab_id = ? ORDER BY sort_order, id",
(tab_id,),
)
)
by_std = {}
for r in old:
sn = r["std_name"] or ""
sn = ALIAS.get(sn, sn)
if sn and sn not in by_std:
by_std[sn] = r
target_std = {x[0] for x in items}
added, renamed, dropped = [], [], []
order = 3
for std, cn, typ, req, note in items:
order += 1
col = by_std.get(std)
if col is not None:
if col["name"] != cn:
# 列改名:字段表里同组同名的一起改,避免字段与列脱钩
conn.execute(
"UPDATE fields SET name = ? WHERE group_id = ? AND name = ?",
(cn, gid, col["name"]),
)
conn.execute("UPDATE columns SET name = ? WHERE id = ?", (cn, col["id"]))
renamed.append("%s → %s" % (col["name"], cn))
conn.execute(
"UPDATE columns SET std_name = ?, std_type = ?, required = ?,"
" std_note = ?, sort_order = ? WHERE id = ?",
(std, typ, req, note, order, col["id"]),
)
else:
fid = conn.execute(
"SELECT id FROM fields WHERE group_id = ? AND name = ?", (gid, cn)
).fetchone()
if fid is None:
conn.execute(
"INSERT INTO fields(name, note, is_value, sort_order, created_at,"
" group_id) VALUES(?,?,0,?,?,?)",
(cn, note, order, app.now_str(), gid),
)
conn.execute(
"INSERT INTO columns(tab_id, name, kind, sort_order, width, created_at,"
" std_name, std_type, required, std_note) VALUES(?,?,?,?,0,?,?,?,?,?)",
(tab_id, cn, "custom", order, app.now_str(), std, typ, req, note),
)
added.append(cn)
# 清掉 COS4 里不存在的标准列(只删有 std_name 的,手工列不动)
for r in old:
if r["kind"] in FIXED_KINDS or not (r["std_name"] or ""):
continue
sn = ALIAS.get(r["std_name"], r["std_name"])
if sn in target_std:
continue
n = conn.execute(
"SELECT COUNT(*) AS c FROM row_values WHERE col_id = ? AND TRIM(value) <> ''",
(r["id"],),
).fetchone()["c"]
conn.execute("DELETE FROM row_values WHERE col_id = ?", (r["id"],))
conn.execute("DELETE FROM fields WHERE group_id = ? AND name = ?", (gid, r["name"]))
conn.execute("DELETE FROM columns WHERE id = ?", (r["id"],))
dropped.append("%s(%s,清 %d 个值)" % (r["name"], r["std_name"], n))
app.sync_field_groups(conn)
print("=" * 68)
print("[%d] %-10s %s 共 %d 列" % (tab_id, tab["name"], element, len(items)))
if added:
print(" + 新增:", "、".join(added))
if renamed:
print(" ~ 改名:", "、".join(renamed))
if dropped:
print(" - 删除:", "、".join(dropped))
if apply:
conn.commit()
print("\n已提交")
else:
conn.rollback()
print("\n预演结束(未提交)")
finally:
conn.close()
if __name__ == "__main__":
main(apply="--apply" in sys.argv)

62
AdminCost/_cos4_source.py Normal file
View File

@@ -0,0 +1,62 @@
# -*- coding: utf-8 -*-
"""COS4 字段来源:两份 COS4 的属性全集 + 已有中文名映射。
字段口径:两家并集(用户 2026-10-29「把 2 家的字段都收集」)。
"""
import json
import os
import sqlite3
BASE = os.path.dirname(os.path.abspath(__file__))
DB = os.path.join(BASE, "data.db")
COS4_JSON = os.path.join(BASE, "参考资料", "规范与COS4", "两份COS4_结构.json")
# 两份 COS4 都没给出中文名、由我们补的 5 个(都是「行里的行」级属性)
EXTRA = {
"Area": ("面积", "Double", 0, "含量表达式涉及的面积"),
"BuildingComponents": ("建筑部位", "String", 0, "所属建筑部位"),
"Explain": ("说明", "String", 0, "补充说明"),
"OrderNumber": ("序号", "Integer", 0, "排序号"),
"Content": ("内容", "String", 0, "服务内容"),
}
_cache = {}
def _load():
if "props" in _cache:
return _cache
data = json.load(open(COS4_JSON, encoding="utf-8"))
props = {}
for ent in data.values():
for scope in ("attrs", "unit_attrs"):
for el, attrs in ent.get(scope, {}).items():
props.setdefault(el, [])
for a in attrs:
if a not in props[el]:
props[el].append(a)
_cache["props"] = props
field = {}
conn = sqlite3.connect(DB)
conn.row_factory = sqlite3.Row
for r in conn.execute(
"SELECT std_name, name, std_type, required, std_note FROM columns"
" WHERE std_name IS NOT NULL AND std_name <> '' ORDER BY id"
):
field.setdefault(r["std_name"].strip(), (r["name"], r["std_type"], r["required"],
r["std_note"] or ""))
conn.close()
field.update(EXTRA)
_cache["field"] = field
return _cache
def props_of(element):
"""该元素的 COS4 属性列表(保序,两家并集)"""
return _load()["props"].get(element, [])
def field_def(std):
"""属性英文名 -> (中文列名, 数据类型, 是否必填, 说明)"""
return _load()["field"].get(std, (std, "String", 0, ""))

220
AdminCost/_cos4_sub.py Normal file
View File

@@ -0,0 +1,220 @@
"""按两份 COS4 校准子表节点的列。
口径(2026-10-29 用户定):数据结构以 2 份 COS4 为准,结合标准规范;COS4 里没有的,我们也不建。
本脚本做三件事:
1. 工料机汇总 34 个属性补上英文属性名(std_name),并删掉 COS4 没有的
风险系数 ProviderRate / 基本价格指数 BasicPrice / 现行价格指数 CurrentPrice
2. 含量明细只有 4 个属性,删掉 COS4 没有的不计价材料 NOCost
3. 五张空表按 COS4 对应元素(含子元素并集)补齐属性列
用法:python _cos4_sub.py [--apply]
"""
import sys
import app
# 中文列名 -> COS4 属性名
CN2STD = {
"工料机编码": "Number",
"名称": "Name",
"型号规格": "Specification",
"单位": "Unit",
"损耗率": "LossRate",
"数量": "Quantity",
"基准单价": "ProviderBase",
"除税定额价": "NoTaxOrgPrice",
"除税价表达式": "NoTaxPriceExpress",
"除税编制价": "NoTaxPrice",
"含税定额价": "TaxOrgPrice",
"含税价表达式": "TaxPriceExpress",
"含税编制价": "TaxPrice",
"除税定额价合价": "NoTaxOrgTotal",
"除税编制价合价": "NoTaxTotal",
"含税定额价合价": "TaxOrgTotal",
"含税编制价合价": "TaxTotal",
"除税率": "TaxRate",
"工料机归属": "Class",
"商品砼": "Concrete",
"工料机类型": "Kind",
"扩展属性": "ExtKind",
"附加属性": "AddiKind",
"主要材料": "MainMaterial",
"暂估价材料": "ProvisionalMaterial",
"供料方式": "Provider",
"变值权重": "Weight",
"价格来源": "PriceSource",
"交货方式": "Delivery",
"送达地点": "Location",
"产地": "ProducingArea",
"厂家": "Supplier",
"质量要求": "Character",
"汇总备注": "Remark",
# 含量明细(LabourMaterialsEquipmentsMachinesElement)只有 4 个属性
"引用编码": "Number",
"数量表达式": "Express",
"消耗量": "Quantity",
"组成备注": "Remark",
}
# COS4 里没有、要删掉的列
DROP = {
2: ["风险系数", "基本价格指数", "现行价格指数"],
8: ["不计价材料"],
}
# 属性中文名(标准表里有就用标准表,没有的按 COS4 语义拟名)
EN2CN = {
"Attr": ("特征", "String"),
"ChapterKind": ("章节类型", "Integer"),
"Chapter": ("章", "Integer"),
"Code": ("代号", "String"),
"Kind": ("类型", "Integer"),
"Name": ("名称", "String"),
"Number": ("编号", "String"),
"Quantity": ("数量", "Double"),
"QtyFormula": ("计算基数", "String"),
"QuantityCalculationRules": ("工程量计算规则", "String"),
"Remark": ("备注", "String"),
"TechnicalAndEconomicIndex": ("技术经济指标", "Double"),
"Total": ("合价(元)", "Double"),
"Unit": ("单位", "String"),
"WorkContent": ("工作内容", "String"),
"CalcType": ("计算方式", "Integer"),
"CalculationKind": ("计算类型", "Integer"),
"CostKind": ("费用类型", "Integer"),
"EquipmentPrice": ("设备单价(元)", "Double"),
"EquipmentTotal": ("设备合价(元)", "Double"),
"ListingIdentity": ("清单标识", "String"),
"LockKind": ("锁定类型", "Integer"),
"Major": ("主要清单", "Boolean"),
"Price": ("单价(元)", "Double"),
"PriceHigh": ("最高限价(元)", "Double"),
"PriceType": ("价格类型", "Integer"),
"Rate": ("费率(%)", "Double"),
"Specialty": ("专业类别", "String"),
"SupplementaryList": ("补充清单", "String"),
"Type": ("类别", "Integer"),
"InitialFee": ("初期费用(元)", "Double"),
"InitialPercent": ("初期费率(%)", "Double"),
"MediumFee": ("中期费用(元)", "Double"),
"MediumPercent": ("中期费率(%)", "Double"),
"LastFee": ("末期费用(元)", "Double"),
"LastPercent": ("末期费率(%)", "Double"),
"Ratios": ("占比(%)", "Double"),
"NormIdentity": ("定额标识", "String"),
"Volume": ("册", "Integer"),
"IsNorm": ("是否定额", "Boolean"),
"EfficiencyKind": ("降效类型", "Integer"),
"IncFeeKind": ("子目增加费类型", "Integer"),
"Predict": ("", "String"),
}
DW = "Attr ChapterKind Code Kind Name Number Quantity QuantityCalculationRules Remark TechnicalAndEconomicIndex Total Unit WorkContent".split()
WE = ("Attr CalcType CalculationKind Code CostKind EquipmentPrice EquipmentTotal Kind ListingIdentity LockKind"
" Major Name Number Price PriceHigh PriceType QtyFormula Quantity QuantityCalculationRules Rate Remark"
" Specialty SupplementaryList Total Type Unit WorkContent").split()
NORM = ("CalculationKind Chapter CostKind EfficiencyKind EquipmentPrice EquipmentTotal IncFeeKind IsNorm Name"
" NormIdentity Number Price Quantity Remark Specialty Total Type Unit Volume").split()
USG = "ChapterKind Code Kind Name Number Quantity Ratios Remark TechnicalAndEconomicIndex Total Unit".split()
USI = "ChapterKind Code Kind Name Number QtyFormula Quantity Rate Ratios Remark TechnicalAndEconomicIndex Total Unit".split()
PWE = ("CalcType Code InitialFee InitialPercent Kind LastFee LastPercent ListingIdentity LockKind MediumFee"
" MediumPercent Name Number Price QtyFormula Quantity Rate Remark Specialty SupplementaryList Total"
" Unit WorkContent").split()
UPWE = PWE + ["PriceType"]
PDW = "Code Kind Name Number Quantity Remark TechnicalAndEconomicIndex Total Unit WorkContent".split()
# tab_id -> [(英文属性, 说明)]
SUB_LAYERS = {
10: ("UnitWorksSummary", USG + [x for x in USI if x not in USG]),
3: ("DivisionalAndElementalWorks", DW + [x for x in WE if x not in DW]),
4: ("Norm", NORM),
5: ("Preliminaries", PWE + [x for x in UPWE if x not in PWE] + [x for x in PDW if x not in PWE]),
6: ("Norm", NORM),
}
def main(apply=False):
app.init_db()
conn = app.connect()
try:
# 1) 工料机汇总 / 含量明细:补属性名,删 COS4 没有的
for tab_id, group_id in ((2, 4), (8, 3)):
tab = conn.execute("SELECT name FROM tabs WHERE id = ?", (tab_id,)).fetchone()
fixed = ("index", "suffix", "action", "anchorline", "anchor")
ph = ",".join("?" * len(fixed))
for r in conn.execute(
"SELECT id, name FROM columns WHERE tab_id = ? AND kind NOT IN (%s)" % ph,
(tab_id,) + fixed,
).fetchall():
std = CN2STD.get(r["name"])
if std:
conn.execute("UPDATE columns SET std_name = ? WHERE id = ?", (std, r["id"]))
for cn in DROP.get(tab_id, []):
row = conn.execute(
"SELECT id FROM columns WHERE tab_id = ? AND name = ?", (tab_id, cn)
).fetchone()
if row is None:
continue
n = conn.execute(
"SELECT COUNT(*) AS c FROM row_values WHERE col_id = ? AND TRIM(value) <> ''",
(row["id"],),
).fetchone()["c"]
conn.execute("DELETE FROM row_values WHERE col_id = ?", (row["id"],))
conn.execute("DELETE FROM fields WHERE group_id = ? AND name = ?", (group_id, cn))
conn.execute("DELETE FROM columns WHERE id = ?", (row["id"],))
print("[%s] 删列:%s(清 %d 个值)" % (tab["name"], cn, n))
# 2) 五张空表按 COS4 元素补属性列
for tab_id, (element, stds) in SUB_LAYERS.items():
tab = conn.execute("SELECT id, name FROM tabs WHERE id = ?", (tab_id,)).fetchone()
gid_row = conn.execute(
"SELECT id FROM field_groups WHERE tab_id = ?", (tab_id,)
).fetchone()
if tab is None or gid_row is None:
print("跳过:%s" % tab_id)
continue
gid = gid_row["id"]
conn.execute("UPDATE tabs SET element = ? WHERE id = ?", (element, tab_id))
order = 3
added = []
for std in stds:
order += 1
if std not in EN2CN:
print(" !! 没有中文名,跳过:%s" % std)
continue
cn, typ = EN2CN[std]
have = conn.execute(
"SELECT id FROM columns WHERE tab_id = ? AND std_name = ?", (tab_id, std)
).fetchone()
if have:
continue
if conn.execute(
"SELECT id FROM fields WHERE group_id = ? AND name = ?", (gid, cn)
).fetchone() is None:
conn.execute(
"INSERT INTO fields(name, note, is_value, sort_order, created_at, group_id)"
" VALUES(?,?,0,?,?,?)",
(cn, "COS4 属性 %s" % std, order, app.now_str(), gid),
)
conn.execute(
"INSERT INTO columns(tab_id, name, kind, sort_order, width, created_at,"
" std_name, std_type, required, std_note) VALUES(?,?,?,?,0,?,?,?,0,?)",
(tab_id, cn, "custom", order, app.now_str(), std, typ, "COS4 属性 %s" % std),
)
added.append(cn)
print("[%s] %s 补 %d 列:%s" % (tab["name"], element, len(added), "、".join(added) or "无"))
app.sync_field_groups(conn)
if apply:
conn.commit()
print("\n已提交")
else:
conn.rollback()
print("\n预演结束(未提交)")
finally:
conn.close()
if __name__ == "__main__":
main(apply="--apply" in sys.argv)

286
AdminCost/_cos4_tree.py Normal file
View File

@@ -0,0 +1,286 @@
"""以两份 COS4 为准,重建目录树(三层各建一套元素节点)。
口径(用户 2026-10-29 定):
· 不再参考规范,数据结构完全以 2 份 COS4 为准,字段取两家的并集;
· 项目层 / 单项工程层 / 单位工程层各建一套节点,一层套一层;
· COS4 元素 45 个全建(含易达独有的 7 个)。
用法:
python _cos4_tree.py 预演(不提交)
python _cos4_tree.py --apply 落库
"""
import sys
import app
from _cos4_source import field_def, props_of
# (key, 节点名, 元素, 父 key, 节点类型, 复用的 tab id)
# 复用 tab 的节点会沿用该 tab 的列与数据;其余新建。
TREE = [
# ------------------------------------------------ 工具页
("base", "基本设置", "", None, "fixed", 1),
# ------------------------------------------------ A 建设项目文件
("A", "建设项目", "ConstructionProject", None, "project", 11),
("A1", "系统信息", "SystemInfo", "A", "table", 16),
("A2", "工程信息", "ConstructionInfo", "A", "table", 17),
("A2.1", "编审信息", "ProjectInfo", "A2", "table", 19),
("A2.2", "招标信息", "TendereeInfo", "A2", "table", 20),
("A2.3", "投标信息", "BidderInfo", "A2", "table", 21),
("A2.4", "工程特征", "AttrInfo", "A2", "table", None),
("A2.4.1", "工程特征项", "AttrInfoItem", "A2.4", "table", 22),
("A2.5", "补充信息", "AddiInfo", "A2", "table", None),
("A2.5.1", "补充信息项", "AddiInfoItem", "A2.5", "table", 23),
("A2.6", "费用精度", "Option", "A2", "table", 18),
("A3", "项目费用汇总", "SummaryOfCost", "A", "table", 24),
("A3.1", "项目其他费用", "AddiCost", "A3", "table", None),
("A4", "建筑安装工程费", "ProjectInstallationWorkCost", "A", "install", 13),
("A4.1", "建安费费用汇总", "ProjectInstallationWorkCostSummary", "A4", "table", None),
("A4.1.1", "建安费汇总组", "ProjectInstallationWorkCostSummaryGroup", "A4.1", "table", None),
("A4.1.2", "建安费汇总项", "ProjectInstallationWorkCostSummaryItem", "A4.1", "table", 25),
("A4.2", "措施项目", "Preliminaries", "A4", "table", None),
("A4.2.1", "措施项目要素", "PreliminaryWorkElement", "A4.2", "table", 5),
("A4.2.2", "措施基本费用汇总", "SummaryOfBasicCost", "A4.2", "table", None),
("A4.2.3", "措施分部分项", "PreliminaryDivisionalWorks", "A4.2", "table", None),
("A4.2.3.1", "措施分部分项要素", "PreliminaryWorkElement", "A4.2.3", "table", None),
("A4.2.3.2", "措施分部分项基本费用", "SummaryOfBasicCost", "A4.2.3", "table", None),
("A4.3", "其他项目", "Sundry", "A4", "table", 26),
("A4.3.1", "其他项目费", "SundryCosts", "A4.3", "table", 27),
("A4.3.1.1", "其他项目费明细", "SundryCostsItem", "A4.3.1", "table", None),
("A4.3.2", "暂列金额", "ProvisionalSums", "A4.3", "table", 28),
("A4.3.2.1", "暂列金额组", "ProvisionalSumsGroup", "A4.3.2", "table", None),
("A4.3.2.2", "暂列金额明细", "ProvisionalSumsItem", "A4.3.2", "table", None),
("A4.3.3", "专业工程暂估价", "SpecialtyProvisionalPrice", "A4.3", "table", 29),
("A4.3.4", "计日工", "DayWorkRate", "A4.3", "table", 30),
("A4.3.4.1", "计日工组", "DayWorkRateGroup", "A4.3.4", "table", None),
("A4.3.5", "总承包服务费", "MainContractorAttendance", "A4.3", "table", 31),
("A4.3.5.1", "总承包服务明细", "MainContractorAttendanceItem", "A4.3.5", "table", None),
("A4.4", "材料暂估价", "ProvisionalMaterialEquipment", "A4", "table", 33),
("A4.5", "增值税", "Tax", "A4", "table", 32),
("A4.6", "建安费工料机汇总", "LabourMaterialsEquipmentsMachinesSummary", "A4", "table", 2),
("A4.6.1", "建安费工料机", "LabourMaterialsEquipmentsMachinesElement", "A4.6", "table", 8),
("A4.7", "变更费用", "ChangeCost", "A4", "table", None),
("A4.8", "索赔费用", "ClaimsCost", "A4", "table", None),
("A4.9", "法规政策变化", "LawsRegulationsAndPolicyChangeProjects", "A4", "table", None),
# ------------------------------------------------ B 单项工程层
("B", "单项工程", "SectionalWorks", None, "sectional", 14),
("B1", "单项工程特征", "AttrInfo", "B", "table", None),
("B1.1", "单项工程特征项", "AttrInfoItem", "B1", "table", None),
("B2", "单项工程费用汇总", "SummaryOfCost", "B", "table", None),
("B2.1", "单项工程其他费用", "AddiCost", "B2", "table", None),
# ------------------------------------------------ C 单位工程层
("C", "单位工程", "UnitWorks", None, "unit", 15),
("C1", "单位工程特征", "AttrInfo", "C", "table", None),
("C1.1", "单位工程特征项", "AttrInfoItem", "C1", "table", None),
("C2", "单位工程补充信息", "AddiInfo", "C", "table", None),
("C2.1", "单位工程补充信息项", "AddiInfoItem", "C2", "table", None),
("C3", "分部分项", "DivisionalAndElementalWorks", "C", "table", None),
("C3.1", "分部工程", "DivisionalWorks", "C3", "table", None),
("C3.2", "清单项目", "WorkElement", "C3", "table", 3),
("C3.2.1", "工作内容", "WorkContent", "C3.2", "table", None),
("C3.2.1.1", "清单定额", "Norm", "C3.2.1", "table", 4),
("C3.2.1.1.1", "清单单价计算", "UnitPriceCalculationOfItem", "C3.2.1.1", "table", None),
("C3.2.1.1.2", "清单定额工料机", "LabourMaterialsEquipmentsMachinesElement", "C3.2.1.1", "table", None),
("C3.2.1.1.3", "含量组成", "ExpressElement", "C3.2.1.1", "table", None),
("C3.2.1.1.4", "定额调整", "NormAdjustmentList", "C3.2.1.1", "table", None),
("C3.2.2", "清单基本费用汇总", "SummaryOfBasicCost", "C3.2", "table", None),
("C3.3", "分部分项基本费用汇总", "SummaryOfBasicCost", "C3", "table", None),
("C4", "单位工程措施项目", "Preliminaries", "C", "table", None),
("C4.1", "单位工程措施项目要素", "UnitWorksPreliminaryWorkElement", "C4", "table", None),
("C4.1.1", "措施要素定额", "Norm", "C4.1", "table", 6),
("C4.1.2", "措施要素工料机", "LabourMaterialsEquipmentsMachinesElement", "C4.1", "table", None),
("C4.1.3", "措施要素单价计算", "UnitPriceCalculationOfItem", "C4.1", "table", None),
("C4.1.4", "措施要素基本费用", "SummaryOfBasicCost", "C4.1", "table", None),
("C4.2", "单位工程措施基本费用", "SummaryOfBasicCost", "C4", "table", None),
("C5", "工料机汇总", "LabourMaterialsEquipmentsMachinesSummary", "C", "table", None),
("C5.1", "工料机", "LabourMaterialsEquipmentsMachinesElement", "C5", "table", None),
("C6", "单位工程其他项目", "Sundry", "C", "table", None),
("C6.1", "单位工程其他项目费", "SundryCosts", "C6", "table", None),
("C6.1.1", "单位工程其他项目费明细", "SundryCostsItem", "C6.1", "table", None),
("C6.2", "单位工程暂列金额", "ProvisionalSums", "C6", "table", None),
("C6.2.1", "单位工程暂列金额组", "ProvisionalSumsGroup", "C6.2", "table", None),
("C6.2.2", "单位工程暂列金额明细", "ProvisionalSumsItem", "C6.2", "table", None),
("C6.3", "单位工程专业暂估价", "SpecialtyProvisionalPrice", "C6", "table", None),
("C6.4", "单位工程计日工", "DayWorkRate", "C6", "table", None),
("C6.4.1", "单位工程计日工组", "DayWorkRateGroup", "C6.4", "table", None),
("C6.5", "单位工程总承包服务费", "MainContractorAttendance", "C6", "table", None),
("C6.5.1", "单位工程总承包服务明细", "MainContractorAttendanceItem", "C6.5", "table", None),
("C7", "单位工程材料暂估价", "ProvisionalMaterialEquipment", "C", "table", None),
("C8", "单位工程增值税", "Tax", "C", "table", None),
("C9", "单位工程费用汇总", "SummaryOfCost", "C", "table", 34),
("C9.1", "单位工程其他费用", "AddiCost", "C9", "table", None),
("C10", "单位工程汇总", "UnitWorksSummary", "C", "table", None),
("C10.1", "单位工程汇总组", "UnitWorksSummaryGroup", "C10", "table", None),
("C10.2", "单位工程汇总项", "UnitWorksSummaryItem", "C10", "table", 10),
]
NO_COLUMN_KINDS = ("index", "suffix", "action", "anchorline", "anchor")
def plan_columns(conn, element, src_tab):
"""该节点应有的列:[(name, std, typ, req, note, width)]"""
cols, seen = [], set()
# 1) 复用 tab 自己的列(保序,含手工列)
if src_tab:
for r in conn.execute(
"SELECT name, std_name, std_type, required, std_note, width, kind FROM columns"
" WHERE tab_id = ? ORDER BY sort_order ASC, id ASC",
(src_tab,),
):
if r["kind"] in NO_COLUMN_KINDS:
continue
cols.append((r["name"], (r["std_name"] or "").strip(), r["std_type"],
r["required"], r["std_note"], r["width"]))
if r["std_name"]:
seen.add(r["std_name"].strip())
# 2) 同元素的其它 tab 作模板
for r in conn.execute(
"SELECT c.name, c.std_name, c.std_type, c.required, c.std_note, c.width"
" FROM columns c JOIN tabs t ON t.id = c.tab_id"
" WHERE t.element = ? AND c.kind = 'custom' AND c.std_name IS NOT NULL"
" AND c.std_name <> '' ORDER BY c.sort_order ASC, c.id ASC",
(element,),
):
std = r["std_name"].strip()
if std in seen:
continue
cols.append((r["name"], std, r["std_type"], r["required"], r["std_note"], r["width"]))
seen.add(std)
# 3) 兜底:按 COS4 属性全集补
for std in props_of(element):
if std in seen:
continue
cn, typ, req, note = field_def(std)
cols.append((cn, std, typ, req, note, 0))
seen.add(std)
return cols
def main(apply=False):
app.init_db()
conn = app.connect()
try:
names = [t[1] for t in TREE]
dup = {n for n in names if names.count(n) > 1}
assert not dup, "节点名重复:%s" % dup
keys = [t[0] for t in TREE]
assert len(keys) == len(set(keys)), "key 重复"
# 先把现有 tab 名改成占位名,避免改名时撞 UNIQUE
for r in conn.execute("SELECT id, name FROM tabs"):
conn.execute("UPDATE tabs SET name = ? WHERE id = ?", ("~t%d~" % r["id"], r["id"]))
# 字段分组名同样是 UNIQUE,一起腾位(顺序最后交给 sync_field_groups 统一)
for r in conn.execute("SELECT id FROM field_groups"):
conn.execute("UPDATE field_groups SET name = ? WHERE id = ?", ("~g%d~" % r["id"], r["id"]))
id_of = {}
for idx, (key, name, element, parent, kind, src) in enumerate(TREE):
if src:
tab_id = src
conn.execute(
"UPDATE tabs SET name = ?, element = ?, node_kind = ?, sort_order = ?,"
" is_fixed = ? WHERE id = ?",
(name, element, kind, idx, 1 if kind == "fixed" else 0, tab_id),
)
else:
cur = conn.execute(
"INSERT INTO tabs(name, is_fixed, sort_order, created_at, parent_id,"
" node_kind, collapsed, element) VALUES(?,?,?,?,?,?,0,?)",
(name, 0, idx, app.now_str(), None, kind, element),
)
tab_id = cur.lastrowid
id_of[key] = tab_id
print("%-10s %-2s %-38s %-46s tab%d" % (key, "", name, element or "-", tab_id))
for idx, (key, name, element, parent, kind, src) in enumerate(TREE):
conn.execute(
"UPDATE tabs SET parent_id = ? WHERE id = ?",
(id_of[parent] if parent else None, id_of[key]),
)
# 列补齐
print("\n" + "=" * 76)
gid_cache = {}
for key, name, element, parent, kind, src in TREE:
tab_id = id_of[key]
g = conn.execute("SELECT id FROM field_groups WHERE tab_id = ?", (tab_id,)).fetchone()
if g is None:
cur = conn.execute(
"INSERT INTO field_groups(name, sort_order, tab_id, created_at)"
" VALUES(?,?,?,?)",
(name, 0, tab_id, app.now_str()),
)
gid = cur.lastrowid
else:
gid = g["id"]
gid_cache[tab_id] = gid
if not element:
continue
want = plan_columns(conn, element, src)
have = {
(r["std_name"] or "").strip(): r["id"]
for r in conn.execute(
"SELECT id, std_name FROM columns WHERE tab_id = ? AND kind = 'custom'",
(tab_id,),
)
}
order, added = 2, []
for cn, std, typ, req, note, width in want:
order += 1
cid = have.get(std) if std else None
if cid:
conn.execute(
"UPDATE columns SET sort_order = ? WHERE id = ?", (order, cid)
)
continue
if conn.execute(
"SELECT 1 FROM columns WHERE tab_id = ? AND name = ?", (tab_id, cn)
).fetchone():
continue
if conn.execute(
"SELECT 1 FROM fields WHERE group_id = ? AND name = ?", (gid, cn)
).fetchone() is None:
conn.execute(
"INSERT INTO fields(name, note, is_value, sort_order, created_at, group_id)"
" VALUES(?,?,0,?,?,?)",
(cn, note or "", order, app.now_str(), gid),
)
conn.execute(
"INSERT INTO columns(tab_id, name, kind, sort_order, width, created_at,"
" std_name, std_type, required, std_note) VALUES(?,?,?,?,?,?,?,?,?,?)",
(tab_id, cn, "custom", order, width or 0, app.now_str(),
std or None, typ, req, note),
)
added.append(cn)
flag = "" if not added else " +%d列" % len(added)
print("%-46s tab%-4d 列%-3d%s" % (name, tab_id, len(want), flag))
app.sync_field_groups(conn)
if apply:
conn.commit()
print("\n已提交")
else:
conn.rollback()
print("\n预演结束(未提交)")
finally:
conn.close()
if __name__ == "__main__":
main(apply="--apply" in sys.argv)

892
AdminCost/_std_attrs.json Normal file
View File

@@ -0,0 +1,892 @@
{
"Number": [
"项目编号",
"String",
"√"
],
"Name": [
"项目名称",
"String",
"√"
],
"FileKind": [
"文件类型",
"Integer",
"√"
],
"ValuationMethod": [
"计价类别",
"Integer",
"√"
],
"TaxModel": [
"计税模式",
"Integer",
"√"
],
"StandardName": [
"数据交换标准名称",
"String",
"√"
],
"StandardNumber": [
"数据交换标准编号",
"String",
"√"
],
"Scale": [
"建设规模",
"Double",
"√"
],
"ScaleUnit": [
"建设规模单位",
"String",
"√"
],
"MaterialPriceDate": [
"材料价格时间",
"String",
"√"
],
"Explains": [
"总说明",
"String",
""
],
"ID1": [
"编制软件信息",
"String",
""
],
"ID2": [
"编制机器硬件信息",
"String",
""
],
"MakeDate": [
"文件生成时间",
"Datetime",
"√"
],
"ResPrecision": [
"工料机消耗量、含量、数量类小数精度",
"Integer",
"√"
],
"QuantityPrecision": [
"工程量、数量类小数精度",
"Integer",
"√"
],
"CostPrecision": [
"金额、合价、费用类小数精度",
"Integer",
"√"
],
"RatePrecision": [
"费率、指数、比率(%)类小数精度",
"Integer",
"√"
],
"Designer": [
"设计单位",
"String",
""
],
"Contractor": [
"承包单位",
"String",
""
],
"CompileCompany": [
"编制单位",
"String",
"√"
],
"Authorizer": [
"编制单位法定代表人或其授权人",
"String",
""
],
"Compiler": [
"编制人员",
"String",
""
],
"CompilerCertNo": [
"编制人员资格证书编号",
"String",
""
],
"CompileDate": [
"编制时间",
"String",
"√"
],
"Examiner": [
"审核人",
"String",
""
],
"ExaminerCertNo": [
"审核人资格证书编号",
"String",
""
],
"ExamineDate": [
"审核时间",
"String",
""
],
"Approver": [
"审定人",
"String",
""
],
"ApproverCertNo": [
"审定人资格证书编号",
"String",
""
],
"ApproverDate": [
"审定时间",
"String",
""
],
"Total": [
"工程总价(元)",
"Double",
"√"
],
"Tenderername": [
"招标人",
"String",
"√"
],
"TenderAuthorizer": [
"招标单位法定代表人或其授权人",
"String",
""
],
"TenderCompiler": [
"招标人编制人员",
"String",
""
],
"TenderCompilerCertNo": [
"招标人编制人员资格证书编号",
"String",
""
],
"TenderCompileDate": [
"招标人编制时间",
"String",
""
],
"TenderExaminer": [
"招标人审核人",
"String",
""
],
"TenderExaminerCertNo": [
"招标人审核人资格证书编号",
"String",
""
],
"TenderExamineDate": [
"招标人审核时间",
"String",
""
],
"TenderApprover": [
"招标人审定人",
"String",
""
],
"TenderApproverCertNo": [
"招标人审定人资格证书编号",
"String",
""
],
"TenderApproveDate": [
"招标人审定时间",
"String",
""
],
"Proxy": [
"招标代理",
"String",
"√"
],
"ProxyCertNo": [
"招标代理资质证书编号",
"String",
""
],
"ProxyAuthorizer": [
"招标代理法定代表人或其授权人",
"String",
""
],
"ProxyCompiler": [
"招标代理编制人员",
"String",
""
],
"ProxyCompilerCertNo": [
"招标代理编制人员资格证书编号",
"String",
""
],
"ProxyCompileDate": [
"招标代理编制时间",
"String",
""
],
"ProxyExaminer": [
"招标代理审核人",
"String",
""
],
"ProxyExaminerCertNo": [
"招标代理审核人资格证书编号",
"String",
""
],
"ProxyExamineDate": [
"招标代理审核时间",
"String",
""
],
"ProxyApprover": [
"招标代理审定人",
"String",
""
],
"ProxyApproverCertNo": [
"招标代理审定人资格证书编号",
"String",
""
],
"ProxyApproveDate": [
"招标代理审定时间",
"String",
""
],
"Consultant": [
"造价咨询",
"String",
"√"
],
"ConsultantCertNo": [
"造价咨询资质证书编号",
"String",
""
],
"ConsultantAuthorizer": [
"造价咨询法定代表人或其授权人",
"String",
""
],
"ConsultantCompiler": [
"造价咨询编制人员",
"String",
""
],
"ConsultantCompilerCertNo": [
"造价咨询编制人员资格证书编号",
"String",
""
],
"ConsultantCompileDate": [
"造价咨询编制时间",
"String",
""
],
"ConsultantExaminer": [
"造价咨询审核人",
"String",
""
],
"ConsultantExaminerCertNo": [
"造价咨询审核人资格证书编号",
"String",
""
],
"ConsultantExamineDate": [
"造价咨询审核时间",
"String",
""
],
"ConsultantApprover": [
"造价咨询审定人",
"String",
""
],
"ConsultantApproverCertNo": [
"造价咨询审定人资格证书编号",
"String",
""
],
"ConsultantApproveDate": [
"造价咨询审定时间",
"String",
""
],
"TenderPriceHighLimit": [
"最高投标限价(元)",
"Double",
"√"
],
"BidName": [
"投标人",
"String",
"√"
],
"BidAuthorizer": [
"投标单位法定代表人或其授权人",
"String",
""
],
"BidTotal": [
"投标总价(元)",
"Double",
"√"
],
"BidCompiler": [
"投标人编制人员",
"String",
""
],
"BidCompilerCertNo": [
"投标人编制人员资格证书编号",
"String",
""
],
"BidCompileDate": [
"投标人编制时间",
"String",
""
],
"BidExaminer": [
"投标人审核人",
"String",
""
],
"BidExaminerCertNo": [
"投标人审核人资格证书编号",
"String",
""
],
"BidExamineDate": [
"投标人审核时间",
"String",
""
],
"BidApprover": [
"投标人审定人",
"String",
""
],
"BidApproverCertNo": [
"投标人审定人资格证书编号",
"String",
""
],
"BidApproveDate": [
"投标人审定时间",
"String",
""
],
"Value": [
"内容",
"String",
""
],
"Code": [
"代号",
"String",
""
],
"Remark": [
"备注",
"String",
""
],
"DivisionalAndElementalWorks": [
"分部分项工程费",
"Double",
""
],
"Preliminaries": [
"措施项目费",
"Double",
""
],
"CostForHSE": [
"安全文明施工措施项目费",
"Double",
""
],
"OtherPreliminaries": [
"其他措施费",
"Double",
""
],
"SundryCosts": [
"其他项目费",
"Double",
""
],
"ProvisionalSums": [
"暂列金额",
"Double",
""
],
"ProvisionalMaterial": [
"暂估价材料",
"Double",
""
],
"SpecialtyProvisionalPrice": [
"专业工程暂估价",
"Double",
""
],
"DayWorkRate": [
"计日工费用",
"Double",
""
],
"MainContractorAttendance": [
"总承包服务费",
"Double",
""
],
"ClaimForLossAndExpenses": [
"索赔费用",
"Double",
""
],
"SiteInstruction": [
"现场签证费用",
"Double",
""
],
"StatutoryFees": [
"规费",
"Double",
""
],
"Tax": [
"税金/增值税销项税额",
"Double",
""
],
"Labor": [
"人工费",
"Double",
""
],
"Material": [
"材料费(不含主材费)",
"Double",
""
],
"MainMaterialEquipment": [
"主材设备费",
"Double",
""
],
"MainMaterial": [
"主材费",
"Double",
""
],
"Equipment": [
"设备费",
"Double",
""
],
"Machine": [
"机械费",
"Double",
""
],
"Overhead": [
"管理费",
"Double",
""
],
"RiskRate": [
"风险费",
"Double",
""
],
"Profit": [
"利润",
"Double",
""
],
"Specification": [
"型号规格及材质",
"String",
""
],
"Unit": [
"单位",
"String",
""
],
"Quantity": [
"数量",
"Double",
""
],
"Price": [
"单价(元)",
"Double",
""
],
"Kind": [
"类型",
"Integer",
""
],
"QtyFormula": [
"计算基数",
"String",
""
],
"Rate": [
"费率(%)",
"Double",
""
],
"Ratios": [
"占整个项目费用比率(%)",
"Double",
""
],
"Rule": [
"计算方法说明",
"String",
""
],
"Segment": [
"标段名称",
"String",
""
],
"Specialty": [
"专业类别",
"String",
"√"
],
"ProviderRate": [
"风险系数(%)",
"Double",
""
],
"ProviderBase": [
"基准单价(元)",
"Double",
""
],
"TaxRate": [
"除税率(%)",
"Double",
""
],
"NoTaxOrgPrice": [
"除税定额价(元)",
"Double",
""
],
"NoTaxPrice": [
"除税编制价(元)",
"Double",
""
],
"TaxOrgPrice": [
"含税定额价(元)",
"Double",
""
],
"TaxPrice": [
"含税编制价(元)",
"Double",
""
],
"NoTaxOrgTotal": [
"除税定额价合价(元)",
"Double",
""
],
"NoTaxTotal": [
"除税编制价合价(元)",
"Double",
""
],
"TaxOrgTotal": [
"含税定额价合价(元)",
"Double",
""
],
"TaxTotal": [
"含税编制价合价(元)",
"Double",
""
],
"Weight": [
"变值权重",
"Double",
""
],
"BasicPrice": [
"基本价格指数",
"Double",
""
],
"CurrentPrice": [
"现行价格指数",
"Double",
""
],
"Class": [
"工料机归属",
"String",
"√"
],
"ExtKind": [
"扩展属性",
"Integer",
""
],
"Concrete": [
"商品砼",
"Boolean",
""
],
"AddiKind": [
"附加属性",
"String",
""
],
"Provider": [
"供料方式",
"Integer",
""
],
"Delivery": [
"交货方式",
"String",
""
],
"Location": [
"送达地点",
"String",
""
],
"ProducingArea": [
"产地",
"String",
""
],
"Supplier": [
"厂家",
"String",
""
],
"Character": [
"质量要求",
"String",
""
],
"NOCost": [
"不计价材料",
"Boolean",
"√"
],
"LimitedPrice": [
"最高限价(元)",
"Double",
""
],
"ResClassValue": [
"控制价(元)",
"Double",
""
],
"ProviderExp": [
"运算符",
"Integer",
""
],
"DeliPlace": [
"送达地点",
"String",
""
],
"Purposes": [
"工程用途",
"String",
""
],
"BillDataBase": [
"清单库",
"String",
""
],
"NormDataBase": [
"定额库",
"String",
""
],
"Appraisal": [
"暂估价",
"Double",
""
],
"Attr": [
"特征",
"String",
""
],
"WorkContent": [
"工作内容",
"String",
""
],
"OriginalPrice": [
"调整前单价(元)",
"Double",
""
],
"PriceLow": [
"最低限价(元)",
"Double",
""
],
"PriceHigh": [
"最高限价(元)",
"Double",
""
],
"OriginalRate": [
"调整前费率(%)",
"Double",
""
],
"OriginalTotal": [
"调整前合价(元)",
"Double",
""
],
"Major": [
"主要清单",
"Boolean",
""
],
"CalcType": [
"计算方式",
"Integer",
"√"
],
"ListingIdentity": [
"清单标识",
"String",
""
],
"OrderNumber": [
"序号",
"String",
"√"
],
"Express": [
"工程量计算式",
"String",
"√"
],
"NormLabor": [
"定额人工费(元)",
"Double",
""
],
"EfficiencyKind": [
"降效类型",
"Integer",
""
],
"IncFeeKind": [
"子目增加费类型",
"Integer",
""
],
"Conversion": [
"换算说明",
"String",
""
],
"NormIdentity": [
"定额标识",
"String",
""
],
"Volume": [
"册",
"Integer",
""
],
"Chapter": [
"章",
"Integer",
""
],
"SettlementTotal": [
"结算金额(元)",
"Double",
""
],
"CalBasis": [
"计算基础",
"String",
""
],
"ProvisionalTotal": [
"暂估金额(元)",
"Double",
""
],
"TotalDifference": [
"差额±(元)",
"Double",
""
],
"ProvisionalQuantity": [
"暂估数量",
"Double",
""
],
"ProvisionalPrice": [
"暂估单价(元)",
"Double",
""
],
"PriceDifference": [
"单价差额±(元)",
"Double",
""
],
"Content": [
"工程内容",
"String",
""
],
"Reason": [
"索赔依据",
"String",
""
]
}

156
AdminCost/_std_schema.py Normal file
View File

@@ -0,0 +1,156 @@
"""按《建设工程造价数据交换标准》给各层级节点建属性列。
「工程费用」层按两家造价软件的一致做法不建(项目直接进入建筑安装工程费)。
列 = 标准属性:中文列名 + 英文属性名(std_name)+ 数据类型 + 是否必填。
同时在「字段设置」里给该节点建同名同分组的字段,保证界面与标准一一对应。
"""
import sys
import app
# (英文属性名, 中文列名, 类型, 必填, 说明)
TABLES = {
11: (
"ConstructionProject",
[
("Number", "项目编号", "String", 1, "建设项目的唯一编号"),
("Name", "项目名称", "String", 1, "建设项目名称"),
("FileKind", "文件类型", "Integer", 1, "1投资估算/2设计概算/3施工图预算/4工程量清单/5最高投标限价/6投标报价/7签约合同价/8结算价"),
("ValuationMethod", "计价类别", "Integer", 1, "1清单计价/2定额计价/3全费用清单计价"),
("TaxModel", "计税模式", "Integer", 1, "1一般计税法/2简易计税法/3营业税计税法"),
("StandardName", "标准名称", "String", 1, "数据交换标准名称"),
("StandardNumber", "标准编号", "String", 1, "数据交换标准编号"),
("Scale", "建设规模", "Double", 1, "只填数字部分,如 20000"),
("ScaleUnit", "建设规模单位", "String", 1, "如 ㎡、km"),
("MaterialPriceDate", "材料价格时间", "String", 1, "精确到月,YYYY-MM"),
("Explains", "总说明", "String", 0, "项目总说明"),
],
),
13: (
"ProjectInstallationWorkCost",
[
("Name", "工程名称", "String", 1, "建筑安装工程费名称"),
("Total", "金额(元)", "Double", 0, "金额,单位元"),
("Scale", "建设规模", "Double", 0, "只填数字部分"),
("Code", "费用代号", "String", 0, "费用代号"),
("Remark", "备注", "String", 0, "备注"),
],
),
14: (
"SectionalWorks",
[
("Number", "工程编号", "String", 0, "单项工程编号"),
("Name", "工程名称", "String", 1, "单项工程名称"),
("Segment", "标段名称", "String", 0, "所属标段"),
("Total", "金额(元)", "Double", 0, "金额,单位元"),
("Specialty", "专业类别", "String", 1, "见标准表 4.2.1-2,如 01 房屋建筑与装饰工程"),
("Scale", "建设规模", "Double", 1, "只填数字部分"),
("ScaleUnit", "建设规模单位", "String", 1, "如 ㎡、km"),
("Ratios", "占项目费用比率(%)", "Double", 0, "占整个项目费用比率"),
("Code", "费用代号", "String", 0, "费用代号"),
("Remark", "备注", "String", 0, "备注"),
],
),
15: (
"UnitWorks",
[
("Number", "工程编号", "String", 1, "单位工程编号"),
("Name", "工程名称", "String", 1, "单位工程名称"),
("Segment", "标段名称", "String", 0, "所属标段"),
("ValuationMethod", "计价类别", "Integer", 1, "1清单计价/2定额计价"),
("TaxModel", "计税模式", "Integer", 1, "1一般计税法/2简易计税法/3营业税计税法"),
("Total", "金额(元)", "Double", 0, "金额,单位元"),
("Specialty", "专业类别", "String", 1, "见标准表 4.2.1-2"),
("Purposes", "工程用途", "String", 0, "工程用途"),
("Scale", "建设规模", "Double", 0, "只填数字部分"),
("ScaleUnit", "建设规模单位", "String", 0, "如 ㎡、km"),
("BillDataBase", "清单库", "String", 0, "所用清单库"),
("NormDataBase", "定额库", "String", 0, "所用定额库"),
("Code", "费用代号", "String", 0, "费用代号"),
("Explains", "总说明", "String", 0, "单位工程总说明"),
("Remark", "备注", "String", 0, "备注"),
],
),
}
# 子表节点对应的标准元素名
SUB_ELEMENTS = {
2: "LabourMaterialsEquipmentsMachinesSummary",
8: "LabourMaterialsEquipmentsMachinesElement",
10: "UnitWorksSummary",
3: "DivisionalAndElementalWorks",
4: "Norm",
5: "Preliminaries",
6: "Norm",
}
def main(apply=False):
app.init_db()
conn = app.connect()
try:
changed = 0
for tab_id, (element, items) in TABLES.items():
tab = conn.execute("SELECT id, name FROM tabs WHERE id = ?", (tab_id,)).fetchone()
if tab is None:
print("跳过:标签 %s 不存在" % tab_id)
continue
conn.execute("UPDATE tabs SET element = ? WHERE id = ?", (element, tab_id))
gid = conn.execute(
"SELECT id FROM field_groups WHERE tab_id = ?", (tab_id,)
).fetchone()
if gid is None:
print("跳过:%s 没有字段分组" % tab["name"])
continue
gid = gid["id"]
order = conn.execute(
"SELECT COALESCE(MAX(sort_order), 0) AS o FROM columns WHERE tab_id = ?",
(tab_id,),
).fetchone()["o"]
for std, cn, typ, req, note in items:
order += 1
fid = conn.execute(
"SELECT id FROM fields WHERE group_id = ? AND name = ?", (gid, cn)
).fetchone()
if fid is None:
cur = conn.execute(
"INSERT INTO fields(name, note, is_value, sort_order, created_at,"
" group_id) VALUES(?,?,0,?,?,?)",
(cn, note, order, app.now_str(), gid),
)
fid = cur.lastrowid
col = conn.execute(
"SELECT id FROM columns WHERE tab_id = ? AND name = ?", (tab_id, cn)
).fetchone()
if col is None:
conn.execute(
"INSERT INTO columns(tab_id, name, kind, sort_order, width,"
" created_at, std_name, std_type, required, std_note)"
" VALUES(?,?,?,?,0,?,?,?,?,?)",
(tab_id, cn, "custom", order, app.now_str(), std, typ, req, note),
)
changed += 1
else:
conn.execute(
"UPDATE columns SET std_name = ?, std_type = ?, required = ?,"
" std_note = ? WHERE id = ?",
(std, typ, req, note, col["id"]),
)
print("%-12s 建列 %d 条(元素 %s)" % (tab["name"], len(items), element))
for tab_id, element in SUB_ELEMENTS.items():
conn.execute("UPDATE tabs SET element = ? WHERE id = ?", (element, tab_id))
app.sync_field_groups(conn)
if apply:
conn.commit()
print("已提交")
else:
conn.rollback()
print("预演结束(未提交)")
print("新增列数:", changed)
finally:
conn.close()
if __name__ == "__main__":
main(apply="--apply" in sys.argv)

136
AdminCost/_tree_v2.py Normal file
View File

@@ -0,0 +1,136 @@
# -*- coding: utf-8 -*-
"""把扁平的 8 个标签改造成「标准层级目录树」。
树形(按《建设工程造价数据交换标准》4.1.1 / 4.1.13 / 4.1.14 / 4.1.23 / 4.2.1):
建设项目
└ 工程费用
└ 建筑安装工程费
└ 单项工程
└ 单位工程
├ 单位工程费用汇总
├ 分部分项清单
├ 分部分项定额
├ 措施项目清单
├ 措施项目定额
└ 工料机汇总
└ 工料机含量明细
"""
import os
import sqlite3
import datetime
BASE = os.path.dirname(os.path.abspath(__file__))
DB = os.path.join(BASE, "data.db")
def now_str():
return datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
def has_col(conn, table, col):
return any(r[1] == col for r in conn.execute("PRAGMA table_info(%s)" % table))
def main():
conn = sqlite3.connect(DB)
conn.row_factory = sqlite3.Row
try:
for col, ddl in (
("parent_id", "INTEGER REFERENCES tabs(id) ON DELETE CASCADE"),
("node_kind", "TEXT NOT NULL DEFAULT 'table'"),
("collapsed", "INTEGER NOT NULL DEFAULT 0"),
):
if not has_col(conn, "tabs", col):
conn.execute("ALTER TABLE tabs ADD COLUMN %s %s" % (col, ddl))
print("++ tabs.%s" % col)
def find(name):
r = conn.execute("SELECT id FROM tabs WHERE name = ?", (name,)).fetchone()
return r["id"] if r else None
def add(name, parent, kind, order):
tid = find(name)
if tid is None:
cur = conn.execute(
"INSERT INTO tabs(name, is_fixed, sort_order, created_at, parent_id,"
" node_kind, collapsed) VALUES(?,0,?,?,?,?,0)",
(name, order, now_str(), parent, kind),
)
tid = cur.lastrowid
print("++ 节点:%s(parent=%s, %s)" % (name, parent, kind))
else:
conn.execute(
"UPDATE tabs SET parent_id=?, node_kind=?, sort_order=? WHERE id=?",
(parent, kind, order, tid),
)
print("~~ 更新节点:%s(parent=%s)" % (name, parent))
return tid
t_proj = add("建设项目", None, "project", 1)
t_cost = add("工程费用", t_proj, "cost", 1)
t_inst = add("建筑安装工程费", t_cost, "install", 1)
t_sect = add("单项工程", t_inst, "sectional", 1)
t_unit = add("单位工程", t_sect, "unit", 1)
# 现有数据标签挂到「单位工程」下
leaves = [
("单位工程费用汇总", 1),
("分部分项清单", 2),
("分部分项定额", 3),
("措施项目清单", 4),
("措施项目定额", 5),
("工料机汇总", 6),
]
t_sum = None
for name, order in leaves:
tid = find(name)
if tid is None:
print("!! 找不到标签:%s" % name)
continue
if name == "工料机汇总":
t_sum = tid
conn.execute(
"UPDATE tabs SET parent_id=?, node_kind='table', sort_order=? WHERE id=?",
(t_unit, order, tid),
)
print("-> 挂载:%s → 单位工程(序 %d)" % (name, order))
# 含量明细挂到工料机汇总下
tid = find("工料机含量明细")
if tid is not None and t_sum is not None:
conn.execute(
"UPDATE tabs SET parent_id=?, node_kind='table', sort_order=1 WHERE id=?",
(t_sum, tid),
)
print("-> 挂载:工料机含量明细 → 工料机汇总")
# 固定标签不属于树
conn.execute(
"UPDATE tabs SET parent_id=NULL, node_kind='fixed' WHERE is_fixed=1"
)
conn.commit()
print("\n==== 目录树 ====")
def walk(pid, depth, prefix):
rows = list(
conn.execute(
"SELECT id, name, node_kind, is_fixed FROM tabs"
" WHERE (parent_id IS ? OR parent_id = ?)"
" AND (is_fixed=0 OR ? IS NULL)"
" ORDER BY sort_order ASC, id ASC",
(pid, pid, pid),
)
)
for i, r in enumerate(rows, 1):
no = ("%s%d" % (prefix, i)) if prefix else str(i)
print(" " * depth + "%-10s %s [%s]" % (no, r["name"], r["node_kind"]))
walk(r["id"], depth + 1, no + ".")
walk(None, 0, "")
finally:
conn.close()
if __name__ == "__main__":
main()

2991
AdminCost/app.py Normal file

File diff suppressed because it is too large Load Diff

2636
AdminCost/index.html Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,70 @@
# -*- coding: utf-8 -*-
"""规范(2018)第6章 vs 两份 COS4 —— 最终对比汇总"""
import json, re, os
BASE = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
SPEC = json.load(open(os.path.join(BASE, "DBJT15-145-2018_第6章_属性表.json"), encoding="utf-8"))
COS = json.load(open(os.path.join(BASE, "两份COS4_结构.json"), encoding="utf-8"))
FIX = {"其他项目费明细": "SundryCostsItem"}
def norm(s):
return re.sub(r"\s+", "", s)
spec_el, spec_tbl = {}, {}
for t in SPEC:
el = norm(FIX.get(norm(t["element"]), norm(t["element"])))
props = {norm(r[1]) for r in t["rows"][1:] if len(r) >= 2 and r[1] and r[1] != "属性名称"}
if not el:
continue
spec_el.setdefault(el, set()).update(props)
spec_tbl.setdefault(el, []).append(t["no"])
CONTAINERS = {"ConstructionInfo", "ConstructionSummary", "UnitWorks", "UnitWorksSummary",
"DivisionalAndElementalWorks", "Preliminaries", "Sundry", "AttrInfo", "AddiInfo",
"ProvisionalMaterialEquipment"}
print("规范(2018)第6章:属性表 %d 张,元素 %d 个,属性定义 %d 条\n" % (len(SPEC), len(spec_el), sum(len(v) for v in spec_el.values())))
cos_els = {}
for fname, ent in COS.items():
els = {}
for scope in ("attrs", "unit_attrs"):
for el, props in ent.get(scope, {}).items():
els.setdefault(norm(el), set()).update(props.keys())
cos_els[fname] = els
for fname, els in cos_els.items():
extra = {e: p for e, p in els.items() if e not in spec_el}
priv = {e: p for e, p in extra.items() if e not in CONTAINERS}
cont = {e: p for e, p in extra.items() if e in CONTAINERS}
print("=" * 72)
print(fname)
print(" 有属性元素 %d|规范内 %d|规范有属性表但COS4缺 %d|容器元素(规范无属性表) %d|★规范外 %d"
% (len(els), len(set(els) & set(spec_el)), len(set(spec_el) - set(els)), len(cont), len(priv)))
print(" ★规范第6章完全没有的元素:")
for e in sorted(priv):
print(" - %-44s %d 个属性:%s" % (e, len(priv[e]), ",".join(sorted(priv[e]))[:120]))
print(" 容器元素(规范有该元素、无属性表):%s" % ",".join(sorted(cont)))
# 属性名差异
diffs = []
for e in sorted(set(spec_el) & set(els)):
miss, add = spec_el[e] - els[e], els[e] - spec_el[e]
if miss or add:
diffs.append((e, sorted(miss), sorted(add)))
print(" 属性名有差异的元素 %d 个:" % len(diffs))
for e, m, a in diffs:
print(" %-42s 缺:%s 多:%s" % (e, ",".join(m) or "-", ",".join(a) or "-"))
print()
# 两家 COS4 互比
a, b = list(cos_els.items())
print("=" * 72)
print("两份 COS4 相互差异")
na, nb = set(a[1]), set(b[1])
print(" 共有元素 %d 个" % len(na & nb))
print(" 仅易达有:%s" % ",".join(sorted(na - nb)))
print(" 仅广联达有:%s" % ",".join(sorted(nb - na)))

View File

@@ -0,0 +1,92 @@
# -*- coding: utf-8 -*-
"""解析两份 COS4:元素树 + 每元素属性集合 + 出现次数"""
import zipfile, json, os, re
import xml.etree.ElementTree as ET
from collections import defaultdict, OrderedDict
BASE = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
FILES = [
r"C:\Users\MZ\Desktop\1易达导出骨架.cos4",
r"C:\Users\MZ\Desktop\广联达导出最新架子.COS4",
]
OUT = os.path.join(BASE, "两份COS4_结构.json")
def decode_name(n):
try:
return n.encode("cp437").decode("gbk")
except Exception:
return n
def parse_xml(data):
"""返回 (元素->属性次数, 元素->子元素集合, 元素->出现次数)"""
root = ET.fromstring(data)
attrs = defaultdict(lambda: defaultdict(int))
children = defaultdict(set)
count = defaultdict(int)
def walk(e, parent=None):
tag = e.tag.split("}")[-1]
count[tag] += 1
if parent:
children[parent].add(tag)
for k, v in e.attrib.items():
attrs[tag][k.split("}")[-1]] += 1
for c in list(e):
walk(c, tag)
walk(root)
return root.tag, attrs, children, count
summary = {}
for f in FILES:
key = os.path.basename(f)
z = zipfile.ZipFile(f)
names = [(n, decode_name(n)) for n in z.namelist()]
proj = [n for n, d in names if d.lower().endswith("project.xml")]
units = [(n, d) for n, d in names if not d.lower().endswith("project.xml") and d.lower().endswith(".xml")]
ent = {"file": f, "project_xml": proj, "unit_count": len(units)}
if proj:
data = z.read(proj[0])
root, attrs, children, count = parse_xml(data)
ent["root"] = root
ent["attrs"] = {k: dict(v) for k, v in attrs.items()}
ent["children"] = {k: sorted(v) for k, v in children.items()}
ent["count"] = dict(count)
# 单位工程:取一个最大的作为样本 + 汇总所有
u_attrs = defaultdict(lambda: defaultdict(int))
u_children = defaultdict(set)
u_count = defaultdict(int)
roots = set()
for n, d in units:
try:
r, a, c, cnt = parse_xml(z.read(n))
except Exception as e:
continue
roots.add(r)
for k, v in a.items():
for ak, ac in v.items():
u_attrs[k][ak] = max(u_attrs[k][ak], ac)
for k, v in c.items():
u_children[k] |= v
for k, v in cnt.items():
u_count[k] += v
ent["unit_roots"] = sorted(roots)
ent["unit_attrs"] = {k: dict(v) for k, v in u_attrs.items()}
ent["unit_children"] = {k: sorted(v) for k, v in u_children.items()}
ent["unit_count"] = dict(u_count)
summary[key] = ent
json.dump(summary, open(OUT, "w", encoding="utf-8"), ensure_ascii=False, indent=1)
for k, e in summary.items():
print("=" * 70)
print(k, "root:", e.get("root"), "units:", e.get("unit_count"), e.get("unit_roots"))
print(" 项目文件元素数:", len(e.get("attrs", {})), " 单位工程元素数:", len(e.get("unit_attrs", {})))
print(" 项目属性总数:", sum(len(v) for v in e.get("attrs", {}).values()))
print(" 单位工程属性总数:", sum(len(v) for v in e.get("unit_attrs", {}).values()))
print(" 项目元素:", sorted(e.get("count", {}).keys()))
print("->", OUT)

View File

@@ -0,0 +1,54 @@
# -*- coding: utf-8 -*-
"""规范第 6 章属性表解析(v3:去反斜杠 + 合并 strong)"""
import re, json, html, os
BASE = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
MD = os.path.join(BASE, "DBJT15-145-2018_全文含表格.md")
OUT = os.path.join(BASE, "DBJT15-145-2018_第6章_属性表.json")
lines = open(MD, encoding="utf-8").read().split("\n")
text = "\n".join(lines[5707:18611])
t2 = text.replace("\\", "")
t2 = re.sub(r"</strong>\s*<strong>", "", t2)
t2 = re.sub(r"<strong>|</strong>", "", t2)
def strip_tags(s):
s = re.sub(r"<img[^>]*>", "", s)
s = re.sub(r"<br\s*/?>", " ", s)
s = re.sub(r"<[^>]+>", "", s)
s = s.replace("&nbsp;", " ")
return html.unescape(s).strip()
heads = []
for m in re.finditer(r"表\s*6\s*\.\s*(\d+)\s*\.\s*(\d+)\s*-?\s*(\d*)\s*([^<>\n]{0,60}?)属性定义表", t2):
no = f"6.{m.group(1)}.{m.group(2)}" + (f"-{m.group(3)}" if m.group(3) else "")
heads.append((m.start(), no, m.group(4).strip()))
result = []
for i, (pos, no, name) in enumerate(heads):
nxt = heads[i + 1][0] if i + 1 < len(heads) else len(t2)
chunk = t2[pos:nxt]
tbl = re.search(r"<table>(.*?)</table>", chunk, re.S)
rows = []
if tbl:
for r in re.findall(r"<tr>(.*?)</tr>", tbl.group(1), re.S):
cells = re.findall(r"<td[^>]*>(.*?)</td>", r, re.S)
vals = [strip_tags(c) for c in cells]
if vals:
rows.append(vals)
result.append({"no": no, "element": name.strip(), "rows": rows})
json.dump(result, open(OUT, "w", encoding="utf-8"), ensure_ascii=False, indent=1)
print("tables:", len(result))
tot = 0
nos = []
for t in result:
props = [r[1] for r in t["rows"][1:] if len(r) >= 2 and r[1] and r[1] != "属性名称"]
tot += len(props)
nos.append(t["no"])
print(f"{t['no']:10s} {t['element'][:40]:42s} props={len(props)}")
print("total prop defs:", tot)
missing = []
print("表号序列:", nos)

File diff suppressed because it is too large Load Diff

113
AdminCost/启动.bat Normal file
View File

@@ -0,0 +1,113 @@
@echo off
cd /d "%~dp0"
title <20><>ǩ<EFBFBD><C7A9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>񣨹رձ<D8B1><D5B1><EFBFBD><EFBFBD>ڼ<EFBFBD>ֹͣ<CDA3><D6B9>
set "PORT=8765"
set "FORCE="
if not "%~1"=="" set "PORT=%~1"
if /i "%~2"=="--restart" set "FORCE=1"
rem ---------- <20><> Python ----------
set "PY="
where python >nul 2>nul
if not errorlevel 1 set "PY=python"
if not defined PY (
where py >nul 2>nul
if not errorlevel 1 set "PY=py"
)
if not defined PY (
echo.
echo [<5B><><EFBFBD><EFBFBD>] û<><C3BB><EFBFBD>ҵ<EFBFBD> Python 3<><33>
echo <20><><EFBFBD>Ȱ<EFBFBD>װ Python<6F><6E><EFBFBD><EFBFBD><EFBFBD>ڰ<EFBFBD>װʱ<D7B0><CAB1>ѡ Add Python to PATH<54><48>
echo.
pause
exit /b 1
)
rem ---------- <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Dz<EFBFBD><C7B2><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD> ----------
call :probe
if not "%ALIVE%"=="1" goto :start
if defined FORCE goto :restart
echo.
echo <20><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD>http://127.0.0.1:%PORT%
echo.
echo <20><> Y <20>ٻس<D9BB> -^> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>񣨽<EFBFBD><F1A3A8BD><EFBFBD><EFBFBD>ɽ<EFBFBD><C9BD>̣<EFBFBD><CCA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>´<EFBFBD><C2B4>룩
echo <20><> N <20>ٻس<D9BB> -^> ֻ<><D6BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҳ<EFBFBD><D2B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܵķ<DCB5><C4B7><EFBFBD>
echo.
echo <20><>15 <20>벻ѡ = N<><4E>ֻ<EFBFBD><D6BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҳ<EFBFBD><D2B3>
echo.
choice /c YN /n /t 15 /d N
if errorlevel 2 goto :openonly
:restart
echo.
echo <20><><EFBFBD>ڽ<EFBFBD><DABD><EFBFBD><EFBFBD>ɽ<EFBFBD><C9BD>̡<EFBFBD><CCA1><EFBFBD>
title <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
taskkill /FI "WINDOWTITLE eq <20><>ǩ<EFBFBD><C7A9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*" /T /F >nul 2>nul
title <20><>ǩ<EFBFBD><C7A9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>񣨹رձ<D8B1><D5B1><EFBFBD><EFBFBD>ڼ<EFBFBD>ֹͣ<CDA3><D6B9>
%PY% app.py %PORT% --stop
if errorlevel 1 (
echo.
echo [<5B><><EFBFBD><EFBFBD>] <20>ɽ<EFBFBD><C9BD><EFBFBD>û<EFBFBD>ܽ<EFBFBD><DCBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˿<EFBFBD> %PORT% <20>Ա<EFBFBD>ռ<EFBFBD>ã<EFBFBD><C3A3><EFBFBD>
echo <20><><EFBFBD>ֶ<EFBFBD><D6B6>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>ǩ<EFBFBD><C7A9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>񡹵ĺڴ<C4BA><DAB4>ڣ<EFBFBD><DAA3><EFBFBD>˫<EFBFBD><CBAB><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
echo.
pause
exit /b 1
)
echo <20><><EFBFBD>ˣ<EFBFBD><CBA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>´<EFBFBD><C2B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
echo.
:start
rem ---------- <20>˿ڱ<CBBF><DAB1><EFBFBD><EFBFBD>ij<EFBFBD><C4B3><EFBFBD>ռ<EFBFBD><D5BC> ----------
call :isListening
if "%LISTEN%"=="1" (
echo.
echo [<5B><><EFBFBD><EFBFBD>] <20>˿<EFBFBD> %PORT% <20><><EFBFBD><EFBFBD><EFBFBD>ij<EFBFBD><C4B3><EFBFBD>ռ<EFBFBD><D5BC><EFBFBD>ˣ<EFBFBD><CBA3><EFBFBD><EFBFBD>DZ<EFBFBD><C7B1><EFBFBD><EFBFBD>񣩡<EFBFBD>
echo <20><><EFBFBD><EFBFBD><EFBFBD>˿<EFBFBD><CBBF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>磺<EFBFBD><E7A3BA><EFBFBD><EFBFBD>.bat 8766
echo.
pause
exit /b 1
)
echo Ŀ¼ <20><>%CD%
echo Python <20><>%PY%
echo <20>˿<EFBFBD> <20><>%PORT%
echo.
echo <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>񡭡<EFBFBD> <20>˿ھ<CBBF><DABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
echo <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>Ƶ<EFBFBD><C6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>http://127.0.0.1:%PORT%
echo <20>رձ<D8B1><D5B1><EFBFBD><EFBFBD>ڣ<EFBFBD><DAA3><EFBFBD><EFBFBD><EFBFBD> Ctrl+C<><43><EFBFBD><EFBFBD>ֹͣ<CDA3><D6B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
echo ------------------------------------------------------------
echo.
%PY% app.py %PORT% --open
set "CODE=%ERRORLEVEL%"
echo.
echo ------------------------------------------------------------
echo <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˳<EFBFBD><CBB3><EFBFBD><EFBFBD>˳<EFBFBD><CBB3><EFBFBD> %CODE%<EFBFBD><EFBFBD>
if not "%CODE%"=="0" echo <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD><D0B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>ҡ<EFBFBD>
echo.
pause
exit /b %CODE%
:openonly
echo.
echo <20>Ѵ<EFBFBD><D1B4><EFBFBD><EFBFBD><EFBFBD>ҳ<EFBFBD><D2B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>δ<EFBFBD><CEB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>´<EFBFBD><C2B4>룬<EFBFBD><EBA3AC><EFBFBD><EFBFBD>˫<EFBFBD><CBAB><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD> Y<><59>
start "" "http://127.0.0.1:%PORT%"
ping -n 3 127.0.0.1 >nul
exit /b 0
rem ---------- <20>ӹ<EFBFBD><D3B9>̣<EFBFBD><CCA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD> ----------
:probe
set "ALIVE=0"
%PY% -c "import urllib.request;urllib.request.urlopen('http://127.0.0.1:%PORT%/api/state',timeout=2)" >nul 2>nul
if not errorlevel 1 set "ALIVE=1"
exit /b 0
rem ---------- <20>ӹ<EFBFBD><D3B9>̣<EFBFBD><CCA3>˿<EFBFBD><CBBF>Ƿ񱻼<C7B7><F1B1BBBC><EFBFBD> ----------
:isListening
set "LISTEN=0"
netstat -ano | findstr "LISTENING" | findstr ":%PORT% " >nul
if not errorlevel 1 set "LISTEN=1"
exit /b 0

View File

@@ -0,0 +1,417 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>造价数据标准 · 命名规范与层级设计方案</title>
<style>
:root{
--bg:#f5f6f8; --card:#fff; --line:#e4e7ee; --line2:#cfd4de;
--text:#1b1f27; --muted:#6f7787; --accent:#2563eb; --accent-soft:#eef3ff;
--ok:#15803d; --ok-soft:#eafaf0; --warn:#b45309; --warn-soft:#fef6e7;
--danger:#b91c1c; --danger-soft:#fdeeee;
}
*{box-sizing:border-box;}
body{margin:0;background:var(--bg);color:var(--text);
font-family:"Microsoft YaHei","PingFang SC","Helvetica Neue",Arial,sans-serif;
font-size:14px;line-height:1.75;-webkit-font-smoothing:antialiased;}
.wrap{max-width:1180px;margin:0 auto;padding:28px 22px 80px;}
h1{font-size:24px;margin:0 0 6px;}
h2{font-size:18px;margin:34px 0 12px;padding-left:10px;border-left:4px solid var(--accent);}
h3{font-size:15px;margin:22px 0 8px;color:#2b3444;}
p{margin:8px 0;}
.sub{color:var(--muted);font-size:12.5px;}
.card{background:var(--card);border:1px solid var(--line);border-radius:12px;padding:16px 18px;margin:12px 0;}
.kpis{display:grid;grid-template-columns:repeat(4,1fr);gap:12px;margin:16px 0;}
.kpi{background:#fff;border:1px solid var(--line);border-radius:12px;padding:12px 14px;}
.kpi b{display:block;font-size:22px;line-height:1.2;color:var(--accent);}
.kpi span{font-size:12px;color:var(--muted);}
table{width:100%;border-collapse:collapse;background:#fff;font-size:13px;}
th,td{border:1px solid var(--line);padding:6px 9px;text-align:left;vertical-align:top;}
th{background:#f7f8fb;font-weight:600;color:#3d4553;white-space:nowrap;}
td.c{text-align:center;white-space:nowrap;}
tr:nth-child(even) td{background:#fcfdff;}
code,.mono{font-family:Consolas,"Courier New",monospace;font-size:12.5px;}
.tag{display:inline-block;padding:0 6px;border-radius:5px;font-size:11.5px;line-height:18px;}
.t-ok{background:var(--ok-soft);color:var(--ok);}
.t-fix{background:var(--accent-soft);color:var(--accent);}
.t-miss{background:var(--danger-soft);color:var(--danger);}
.t-ext{background:var(--warn-soft);color:var(--warn);}
/* 层级图 */
.tree{background:#fff;border:1px solid var(--line);border-radius:12px;padding:14px 16px;}
.lv{display:flex;align-items:flex-start;gap:10px;margin:7px 0;}
.lv .badge{flex:0 0 auto;min-width:96px;text-align:center;font-size:12px;padding:3px 8px;border-radius:7px;
background:var(--accent-soft);color:var(--accent);border:1px solid #c9d9f8;}
.lv .box{flex:1 1 auto;border:1px solid var(--line);border-radius:9px;padding:8px 12px;background:#fcfdff;}
.lv .box b{font-size:13px;}
.lv .box .en{color:var(--muted);font-family:Consolas,monospace;font-size:12px;}
.ind1{margin-left:26px;} .ind2{margin-left:52px;} .ind3{margin-left:78px;}
.note{background:var(--warn-soft);border:1px solid #f2d9a8;border-radius:10px;padding:10px 14px;margin:12px 0;}
.note b{color:var(--warn);}
.ok-note{background:var(--ok-soft);border:1px solid #bfe6cd;border-radius:10px;padding:10px 14px;margin:12px 0;}
.ok-note b{color:var(--ok);}
ul,ol{margin:8px 0 8px 22px;padding:0;}
li{margin:4px 0;}
.cols2{display:grid;grid-template-columns:1fr 1fr;gap:14px;}
.wire{background:#fff;border:1px solid var(--line2);border-radius:10px;overflow:hidden;font-size:12.5px;}
.wire .top{background:#f7f8fb;border-bottom:1px solid var(--line);padding:6px 10px;color:var(--muted);}
.wire .body{display:flex;min-height:230px;}
.wire .nav{flex:0 0 168px;border-right:1px solid var(--line);padding:8px;background:#fbfcfe;}
.wire .nav div{padding:3px 6px;border-radius:5px;margin:1px 0;}
.wire .nav div.on{background:var(--accent-soft);color:var(--accent);font-weight:600;}
.wire .main{flex:1 1 auto;padding:8px;}
.row{display:flex;gap:6px;padding:2px 0;}
.cell{border:1px solid var(--line);border-radius:4px;padding:1px 6px;background:#fff;white-space:nowrap;}
.cell.h{background:#f2f5fa;color:#4b5462;}
.dim{color:var(--muted);}
footer{margin-top:40px;color:var(--muted);font-size:12px;border-top:1px solid var(--line);padding-top:12px;}
</style>
</head>
<body>
<div class="wrap">
<h1>造价数据标准 · 命名规范与层级设计方案</h1>
<p class="sub">依据《建设工程造价数据交换标准》(征求意见稿)与两份真实 COS4 导出文件(易达 / 广联达),
校准本软件的列名称,并给出「一层套一层」的结构落地方案。 整理日期:2026-10-29</p>
<div class="kpis">
<div class="kpi"><b>33</b><span>工料机汇总标准属性</span></div>
<div class="kpi"><b>27</b><span>本次按标准改正的列名/字段名</span></div>
<div class="kpi"><b>3+1</b><span>标准有、本系统尚缺的属性</span></div>
<div class="kpi"><b>4 级</b><span>项目→单项→单位→清单/定额 结构深度</span></div>
</div>
<div class="card">
<b>一页结论</b>
<ol>
<li><b>命名口径已统一到标准</b>:属性列一律用标准「中文解释」原词(如 <span class="mono">NoTaxPrice</span>=除税编制价,
不是"除税价";<span class="mono">TaxRate</span>=除税率,不是"税率")。共改 27 处,已落库。</li>
<li><b>枚举类属性(Kind / ExtKind / Provider)保持"一值一列"</b>,列名=枚举标签。<b>Kind 口径已核实</b>:
上传的 COS4 是对的(编码前缀/单位/跨厂商 29 个共有编码零冲突三重印证),与征求意见稿注 2 整体差一位,
本系统按 <b>COS4 口径</b>为准,只在导出给别的系统时 +1 折算(见 §3.4)。另外 <span class="mono">Kind</span> 在 15 种节点上含义各不相同,
必须按锚定行分别命名(见 §3.5)。</li>
<li><b>"一层套一层"不需要新造数据结构</b>:现有的「目录 → 标签页 → 锚定行 → 行(后缀) → 列 → 值列」已经是标准的
五级映射,缺的是<b>两样东西</b>:目录里的"工程结构容器"(项目/单项/单位工程)与表格里的"树形行"(缩进+折叠)。</li>
<li><b>单位工程费用汇总</b>(Group / Item 可无限嵌套)建议用<b>一个锚定行 + 「汇总类型」值列 + 层级编号缩进</b>表达,
不拆两个锚定行——因为标准里这两者的 7 个属性完全相同(见 §5.3)。</li>
</ol>
</div>
<h2>1 标准的节点树(一张图看懂"一层套一层")</h2>
<p>标准是纯 XML 树,本软件要做的其实就是把这棵树映射成「目录 / 标签 / 行 / 列」。
下面是本标准里与本软件相关的层级链(只列主干):</p>
<div class="tree">
<div class="lv"><div class="badge">L1 建设项目</div>
<div class="box"><b>建设项目</b> <span class="en">ConstructionProject</span>
<div class="dim">项目编号 / 项目名称 / 文件类型 / 计价类别 / 计税模式 / 标准名称·编号 / 建设规模 / 材料价格时间 / 总说明(11 属性)</div></div></div>
<div class="lv ind1"><div class="badge">L2 单项工程</div>
<div class="box"><b>单项工程</b> <span class="en">ProjectInstallationWorkCost</span>
<div class="dim">工程编号 / 工程名称 / 标段 / 金额 / 专业类别 / 建设规模 / 占比 / 费用代号 / 备注(10 属性)</div></div></div>
<div class="lv ind2"><div class="badge">L3 单位工程</div>
<div class="box"><b>单位工程</b> <span class="en">UnitWorks</span>
<div class="dim">工程编号 / 名称 / 计价类别 / 计税模式 / 专业类别 / 清单库 / 定额库 / 总说明…(15 属性)</div></div></div>
<div class="lv ind3"><div class="badge">L4 表</div>
<div class="box"><b>单位工程费用汇总</b> <span class="en">UnitWorksSummary</span> → 标题 Group / 明细 Item(<b>可嵌套树</b>,7 属性)</div></div>
<div class="lv ind3"><div class="badge">L4 表</div>
<div class="box"><b>分部分项工程</b> <span class="en">DivisionalAndElementalWorks</span> → 分部工程 DivisionalWorks → 清单 WorkElement / 定额 Norm</div></div>
<div class="lv ind3"><div class="badge">L4 表</div>
<div class="box"><b>措施项目</b> <span class="en">Preliminaries</span>;<b>其他项目</b> <span class="en">Sundry</span>;<b>规费</b> StatutoryFees;<b>税金</b> Tax</div></div>
<div class="lv ind3"><div class="badge">L4 表</div>
<div class="box"><b>工料机汇总</b> <span class="en">LabourMaterialsEquipmentsMachinesSummary</span>(33 属性)</div></div>
<div class="lv ind3"><div class="badge">L5 明细</div>
<div class="box"><b>工料机含量明细</b> <span class="en">LabourMaterialsEquipmentsMachinesElement</span>
<div class="dim">工料机编码 / 消耗量 / 不计价材料 / 备注(4 属性)+ 易达私有 Express(数量表达式)</div></div></div>
<div class="lv ind3"><div class="badge">L6 分析</div>
<div class="box"><b>综合单价分析</b> <span class="en">UnitPriceCalculationOfItem / PriceAnalysis</span> → 定额 Norm → 含量明细 Element → 汇总 Summary(引用)</div></div>
</div>
<div class="ok-note">
<b>关键关系</b>:含量明细(Element)通过 <span class="mono">Number</span>(工料机编码)<b>引用</b>工料机汇总(Summary)里的一条记录;
定额(Norm)通过编码引用定额库;清单(WorkElement)下挂定额、定额下挂含量明细。整棵树靠<b>编码</b>串起来——这就是"关联"的本质。
</div>
<h2>2 工料机汇总属性表(标准 33 条 · 逐条对照本系统列名)</h2>
<p class="sub">表 4.1.24-1。最后一列是本次改名后的结果:<span class="tag t-fix">已改正</span> <span class="tag t-ok">原本一致</span> <span class="tag t-miss">系统缺</span> <span class="tag t-ext">标准外/私有</span></p>
<table>
<thead><tr><th style="width:44px">#</th><th style="width:190px">属性名称</th><th style="width:170px">中文解释(标准)</th><th style="width:70px">类型</th><th style="width:52px">必填</th><th>本系统列名(现状)</th></tr></thead>
<tbody>
<tr><td class="c">1</td><td class="mono">Number</td><td>工料机编码</td><td class="c">String</td><td class="c">√</td><td>工料机编码 <span class="tag t-fix">原「材料编码」</span></td></tr>
<tr><td class="c">2</td><td class="mono">Name</td><td>名称</td><td class="c">String</td><td class="c">√</td><td>名称 <span class="tag t-ok">一致</span></td></tr>
<tr><td class="c">3</td><td class="mono">Specification</td><td>型号规格</td><td class="c">String</td><td class="c"></td><td>型号规格 <span class="tag t-fix">原「规格型号」</span></td></tr>
<tr><td class="c">4</td><td class="mono">Unit</td><td>单位</td><td class="c">String</td><td class="c">√</td><td>单位 <span class="tag t-ok">一致</span></td></tr>
<tr><td class="c">5</td><td class="mono">Quantity</td><td>数量</td><td class="c">Double</td><td class="c"></td><td>数量 <span class="tag t-ok">一致</span></td></tr>
<tr><td class="c">6</td><td class="mono">ProviderRate</td><td>风险系数(%)</td><td class="c">Double</td><td class="c"></td><td><span class="tag t-miss">缺</span></td></tr>
<tr><td class="c">7</td><td class="mono">ProviderBase</td><td>基准单价(元)</td><td class="c">Double</td><td class="c"></td><td>基准单价 <span class="tag t-fix">原「供方基数」</span></td></tr>
<tr><td class="c">8</td><td class="mono">TaxRate</td><td>除税率(%)</td><td class="c">Double</td><td class="c"></td><td>除税率 <span class="tag t-fix">原「税率」</span></td></tr>
<tr><td class="c">9</td><td class="mono">NoTaxOrgPrice</td><td>除税定额价(元)</td><td class="c">Double</td><td class="c"></td><td>除税定额价 <span class="tag t-fix">原「除税原价」</span></td></tr>
<tr><td class="c">10</td><td class="mono">NoTaxPrice</td><td>除税编制价(元)</td><td class="c">Double</td><td class="c"></td><td>除税编制价 <span class="tag t-fix">原「除税价」</span></td></tr>
<tr><td class="c">11</td><td class="mono">TaxOrgPrice</td><td>含税定额价(元)</td><td class="c">Double</td><td class="c"></td><td>含税定额价 <span class="tag t-fix">原「含税原价」</span></td></tr>
<tr><td class="c">12</td><td class="mono">TaxPrice</td><td>含税编制价(元)</td><td class="c">Double</td><td class="c"></td><td>含税编制价 <span class="tag t-fix">原「含税价」</span></td></tr>
<tr><td class="c">13</td><td class="mono">NoTaxOrgTotal</td><td>除税定额价合价(元)</td><td class="c">Double</td><td class="c"></td><td>除税定额价合价 <span class="tag t-fix">原「除税原价合价」</span></td></tr>
<tr><td class="c">14</td><td class="mono">NoTaxTotal</td><td>除税编制价合价(元)</td><td class="c">Double</td><td class="c"></td><td>除税编制价合价 <span class="tag t-fix">原「除税合价」</span></td></tr>
<tr><td class="c">15</td><td class="mono">TaxOrgTotal</td><td>含税定额价合价(元)</td><td class="c">Double</td><td class="c"></td><td>含税定额价合价 <span class="tag t-fix">原「含税原价合价」</span></td></tr>
<tr><td class="c">16</td><td class="mono">TaxTotal</td><td>含税编制价合价(元)</td><td class="c">Double</td><td class="c"></td><td>含税编制价合价 <span class="tag t-fix">原「含税合价」</span></td></tr>
<tr><td class="c">17</td><td class="mono">Weight</td><td>变值权重</td><td class="c">Double</td><td class="c"></td><td>变值权重 <span class="tag t-fix">原「权重」</span></td></tr>
<tr><td class="c">18</td><td class="mono">BasicPrice</td><td>基本价格指数</td><td class="c">Double</td><td class="c"></td><td><span class="tag t-miss">缺</span></td></tr>
<tr><td class="c">19</td><td class="mono">CurrentPrice</td><td>现行价格指数</td><td class="c">Double</td><td class="c"></td><td><span class="tag t-miss">缺</span></td></tr>
<tr><td class="c">20</td><td class="mono">Kind</td><td>工料机类型</td><td class="c">Integer</td><td class="c">√</td><td>工料机类型 <span class="tag t-fix">原「类别」</span>+9 个值列</td></tr>
<tr><td class="c">21</td><td class="mono">Class</td><td>工料机归属</td><td class="c">String</td><td class="c">√</td><td>工料机归属 <span class="tag t-fix">原「分类」</span></td></tr>
<tr><td class="c">22</td><td class="mono">ExtKind</td><td>扩展属性</td><td class="c">Integer</td><td class="c"></td><td>扩展属性 <span class="tag t-fix">原「扩展类别」</span>+4 个值列</td></tr>
<tr><td class="c">23</td><td class="mono">Concrete</td><td>商品砼</td><td class="c">Boolean</td><td class="c"></td><td>商品砼 <span class="tag t-fix">原「是否混凝土」</span></td></tr>
<tr><td class="c">24</td><td class="mono">AddiKind</td><td>附加属性</td><td class="c">String</td><td class="c"></td><td>附加属性 <span class="tag t-fix">原「附加类别」</span></td></tr>
<tr><td class="c">25</td><td class="mono">MainMaterial</td><td>主要材料</td><td class="c">Boolean</td><td class="c"></td><td>主要材料 <span class="tag t-fix">原「是否主材」</span></td></tr>
<tr><td class="c">26</td><td class="mono">ProvisionalMaterial</td><td>暂估价材料</td><td class="c">Boolean</td><td class="c"></td><td>暂估价材料 <span class="tag t-fix">原「是否暂估材料」</span></td></tr>
<tr><td class="c">27</td><td class="mono">Provider</td><td>供料方式</td><td class="c">Integer</td><td class="c"></td><td>供料方式 <span class="tag t-fix">原「供货方式」</span>+3 个值列</td></tr>
<tr><td class="c">28</td><td class="mono">Delivery</td><td>交货方式</td><td class="c">String</td><td class="c"></td><td>交货方式 <span class="tag t-ok">一致</span></td></tr>
<tr><td class="c">29</td><td class="mono">Location</td><td>送达地点</td><td class="c">String</td><td class="c"></td><td>送达地点 <span class="tag t-fix">原「交货地点」</span></td></tr>
<tr><td class="c">30</td><td class="mono">ProducingArea</td><td>产地</td><td class="c">String</td><td class="c"></td><td>产地 <span class="tag t-ok">一致</span></td></tr>
<tr><td class="c">31</td><td class="mono">Supplier</td><td>厂家</td><td class="c">String</td><td class="c"></td><td>厂家 <span class="tag t-fix">原「供应商」</span></td></tr>
<tr><td class="c">32</td><td class="mono">Character</td><td>质量要求</td><td class="c">String</td><td class="c"></td><td>质量要求 <span class="tag t-fix">原「特征」</span></td></tr>
<tr><td class="c">33</td><td class="mono">Remark</td><td>备注</td><td class="c">String</td><td class="c"></td><td>汇总备注 <span class="tag t-ext">按「一个锚定行一个名称」加限定</span></td></tr>
<tr><td class="c">—</td><td class="mono">LossRate</td><td class="dim">(标准无此属性)</td><td class="c">Double</td><td class="c"></td><td>损耗率 <span class="tag t-ext">易达私有</span></td></tr>
<tr><td class="c">—</td><td class="mono">NoTaxPriceExpress</td><td class="dim">(标准无此属性)</td><td class="c">String</td><td class="c"></td><td>除税价表达式 <span class="tag t-ext">易达私有</span></td></tr>
<tr><td class="c">—</td><td class="mono">TaxPriceExpress</td><td class="dim">(标准无此属性)</td><td class="c">String</td><td class="c"></td><td>含税价表达式 <span class="tag t-ext">易达私有</span></td></tr>
<tr><td class="c">—</td><td class="mono">PriceSource</td><td class="dim">(标准无此属性)</td><td class="c">String</td><td class="c"></td><td>价格来源 <span class="tag t-ext">两家都带</span></td></tr>
</tbody>
</table>
<h3>2.1 工料机含量明细(标准 4 条 · 表 4.1.25)</h3>
<table>
<thead><tr><th style="width:44px">#</th><th style="width:190px">属性名称</th><th style="width:170px">中文解释(标准)</th><th style="width:70px">类型</th><th style="width:52px">必填</th><th>本系统列名</th></tr></thead>
<tbody>
<tr><td class="c">1</td><td class="mono">Number</td><td>工料机编码</td><td class="c">String</td><td class="c">√</td><td>引用编码 <span class="tag t-ext">与汇总区分:它只是"引用"</span></td></tr>
<tr><td class="c">2</td><td class="mono">Quantity</td><td>消耗量</td><td class="c">Double</td><td class="c">√</td><td>消耗量 <span class="tag t-ok">一致</span></td></tr>
<tr><td class="c">3</td><td class="mono">NOCost</td><td>不计价材料</td><td class="c">Boolean</td><td class="c">√</td><td><span class="tag t-miss">缺</span></td></tr>
<tr><td class="c">4</td><td class="mono">Remark</td><td>备注</td><td class="c">String</td><td class="c"></td><td>组成备注 <span class="tag t-ext">加限定</span></td></tr>
<tr><td class="c">—</td><td class="mono">Express</td><td class="dim">(标准无此属性)</td><td class="c">String</td><td class="c"></td><td>数量表达式 <span class="tag t-ext">两家都带,= 消耗量的算式</span></td></tr>
</tbody>
</table>
<h2>3 真实文件实测(决定"能不能真导入"的关键)</h2>
<table>
<thead><tr><th>项目</th><th>易达(1易达导出骨架.cos4)</th><th>广联达(广联达导出最新架子.COS4)</th><th>说明</th></tr></thead>
<tbody>
<tr><td>声明标准</td><td>DBJ/T 15-145-2025 v4.00</td><td>DBJ/T 15-145-2025 v4.00</td><td>两家都用<b>广东地标</b>编号,不是国标号</td></tr>
<tr><td>单位工程数</td><td>31 个 XML</td><td>44 个 XML</td><td>一个单位工程一个文件</td></tr>
<tr><td>工料机汇总节点</td><td>156(项目级 54 + 单位工程 102)</td><td>673(项目级 33 + 单位工程 640)</td><td>Summary 挂在 <span class="mono">ProjectInstallationWorkCost</span> 与 <span class="mono">UnitWorks</span> 下</td></tr>
<tr><td>含量明细节点</td><td>399(4 属性:Number/Express/Quantity/Remark)</td><td>1746(4 属性相同)</td><td><b>修正旧结论</b>:广联达也有 Element,之前只统计了 Project.xml</td></tr>
<tr><td>汇总属性覆盖</td><td>32 条</td><td>30 条</td><td>见下</td></tr>
<tr><td>两家都没有</td><td colspan="2">ProviderRate 风险系数、BasicPrice 基本价格指数、CurrentPrice 现行价格指数</td><td>标准有、实际不导 → 建列后留空即可</td></tr>
<tr><td>易达独有</td><td>LossRate 损耗率、NoTaxPriceExpress、TaxPriceExpress、AddiKind 附加属性</td><td>—</td><td>导入时要容忍缺失</td></tr>
<tr><td>广联达独有</td><td>—</td><td>ProviderBase 基准单价、Weight 变值权重(单位工程级)</td><td>导入时要容忍缺失</td></tr>
</tbody>
</table>
<h3>3.4 Kind 枚举:<span style="color:var(--ok)">真实文件的口径已核实无误</span>,与征求意见稿注 2 整体差一位</h3>
<div class="ok-note">
<b>核实结论:上传的 COS4 里 Kind 是对的,不是随手填的。</b>三条硬证据互相咬合:
<ol>
<li><b>编码前缀吻合</b>——<span class="mono">99…</span> 一律是台班(Kind=7);<span class="mono">9945…</span> 是台班的组成项
(折旧费/检修费/维护费/柴油/电,Kind=3);<span class="mono">00010010</span> 人工费(Kind=1)、<span class="mono">00010003</span> 机上人工(Kind=3)。
这是广东定额编码体系,Kind 与编码一一对应。</li>
<li><b>计量单位吻合</b>——Kind=7 全是「台班」;Kind=1/15 全是「元」;Kind=2 是 kg/m³/t/个 等实物单位;Kind=4 是「台/组/m」。</li>
<li><b>跨两家软件零冲突</b>——易达 54 个编码、广联达 47 个,<b>29 个共有编码的 Kind 完全一致,0 例冲突</b>。
两家独立导出还能对齐,说明是行业统一口径。</li>
</ol>
<p>所以判定:<b>实测值 = 标准注 2 的值 − 1</b>(人工 2→1、材料 3→2、机械 4→3、主材 5→4、台班 8→7)。
原因基本可断定:注 2 把「1」留给了"其他",厂商实现里没有这个空位,人工从 1 起排,"其他"挪到 15。两者各自内部自洽,是版本/实现差异。</p>
</div>
<p><b>两条铁律:</b>① 导入与界面<b>一律用 COS4 口径</b>(即本系统现在的 16 个值列,含 15=其他),不要按注 2 校验,
否则材料会被标成人工、台班会被标成配合比;② <b>只在"导出给别的系统"时折算</b>(按 +1 映射,折算表放导入导出模块,界面上不出现第二套编号)。</p>
<table>
<thead><tr><th>来源</th><th>1</th><th>2</th><th>3</th><th>4</th><th>5</th><th>6</th><th>7</th><th>8</th><th>15</th></tr></thead>
<tbody>
<tr><td>标准注 2</td><td class="c">其他</td><td class="c">人工</td><td class="c">材料</td><td class="c">机械</td><td class="c">主材</td><td class="c">设备</td><td class="c">配合比</td><td class="c">机械台班</td><td class="c dim">—</td></tr>
<tr><td>易达实测</td><td class="c">人工费(元)</td><td class="c">材料</td><td class="c">机械</td><td class="c">主材/设备</td><td class="c dim">未见</td><td class="c dim">未见</td><td class="c">台班</td><td class="c dim">未见</td><td class="c dim">未见</td></tr>
<tr><td>广联达实测</td><td class="c">人工费(元)</td><td class="c">材料</td><td class="c">机械</td><td class="c">主材</td><td class="c dim">未见</td><td class="c dim">未见</td><td class="c">台班</td><td class="c dim">未见</td><td class="c">管理费/费用调整</td></tr>
<tr><td><b>本系统现在</b></td><td class="c">人工</td><td class="c">材料</td><td class="c">机械</td><td class="c">主材</td><td class="c">设备</td><td class="c">配合比</td><td class="c">机械台班</td><td class="c">定额材料</td><td class="c">其他</td></tr>
</tbody>
</table>
<p>上表四行一比就看出规律:<b>实测值 = 标准值 − 1</b>。本系统的 16 个值列与 COS4 完全一致,这就是正确口径,<b>维持不动</b>。</p>
<p class="sub">ExtKind:标准 1=普通工料、2=人工降效、3=机械降效、4=暂估价材料;实测两份文件全部为 1,暂无冲突(列名已按标准改「机械降效」「暂估价(扩展)」)。<br>
Provider:1=乙供、2=甲供、3=甲招乙供;实测全部为 1,列名已按标准改「供料方式」。</p>
<h3>3.5 同一个 <span class="mono">Kind</span> 出现在 <span style="color:var(--danger)">15 种节点</span>上,含义完全不同</h3>
<div class="note">
<b>这是最容易出错的地方。</b>标准里的 <span class="mono">Kind</span> 不是全局唯一枚举,它<b>跟着所在节点变意思</b>:
同为 <span class="mono">Kind="1"</span>,在工料机汇总里是「人工」,在费用汇总里是「汇总条目」,在设备费里是「国内设备」,在预备费里是「基本预备费」。
<b>所以列名必须按锚定行分别命名,绝不能全系统共用一列「Kind」。</b>
</div>
<table>
<thead><tr><th>#</th><th>出现节点(=我们的锚定行)</th><th>标准表号</th><th>标准中文名</th><th>枚举</th><th>实测取值</th></tr></thead>
<tbody>
<tr><td class="c">1</td><td><b>LabourMaterialsEquipmentsMachinesSummary</b> 工料机汇总</td><td class="c">4.1.24-1</td><td><b>工料机类型</b></td><td>见 §3.4(与注 2 差一位)</td><td>易达 1/2/3/4/7;广联达 1/2/3/4/7/15</td></tr>
<tr><td class="c">2</td><td>UnitWorksSummaryGroup 单位工程费用汇总·<b>标题</b></td><td class="c">4.2.2-2</td><td>汇总类型</td><td>1=汇总条目;2=不汇总条目</td><td>全为 1(62 / 88 条)</td></tr>
<tr><td class="c">3</td><td>UnitWorksSummaryItem 单位工程费用汇总·<b>明细</b></td><td class="c">4.2.2-3</td><td>汇总类型</td><td>同上</td><td>1=主项(分部分项/增值税/工程造价);2=「其中:xxx」</td></tr>
<tr><td class="c">4</td><td>ProjectInstallationWorkCostSummaryGroup 建设项目费用汇总·标题</td><td class="c">4.1.x-2</td><td>汇总类型</td><td>同上</td><td>全为 1(5 / 5 条)</td></tr>
<tr><td class="c">5</td><td>ProjectInstallationWorkCostSummaryItem 建设项目费用汇总·明细</td><td class="c">4.1.x-3</td><td>汇总类型</td><td>同上</td><td><span class="tag t-miss">两家不一致</span>易达 1=单位工程行、2=其中项;广联达 1=顶层费用(增值税/造价)、2=单位工程行+其中项</td></tr>
<tr><td class="c">6</td><td>ExpressElement 工程量计算表</td><td class="c">4.2.8</td><td>汇总类型</td><td>1=汇总条目;2=不汇总条目</td><td>全为 1(36 条)</td></tr>
<tr><td class="c">7</td><td>SundryCostsGroup / <b>SundryCostsItem</b> 其他项目费</td><td class="c">4.2.18-2/-3</td><td>汇总类型</td><td>同上</td><td>全为 1(68 / 270 条)</td></tr>
<tr><td class="c">8</td><td>ProvisionalSumsGroup / <b>ProvisionalSumsItem</b> 暂列金额</td><td class="c">4.2.19-2/-3</td><td>汇总类型</td><td>同上</td><td>全为 1(96+128 / 180 条)</td></tr>
<tr><td class="c">9</td><td>MainContractorAttendanceGroup / <b>Item</b> 总承包服务费</td><td class="c">4.2.23-2/-3</td><td>汇总类型</td><td>同上</td><td>全为 1(3 / 135 条)</td></tr>
<tr><td class="c">10</td><td>设备及工器具购置费明细</td><td class="c">4.1.16</td><td><b>类型</b></td><td>1=国内设备;2=国外设备</td><td class="dim">本批文件未出现</td></tr>
<tr><td class="c">11</td><td>预备费明细 ContingencyFeeItem</td><td class="c">4.1.19-3</td><td><b>费用类型</b></td><td>1=基本预备费;2=价差预备费</td><td class="dim">本批文件未出现</td></tr>
<tr><td class="c">12</td><td>DivisionalWorks 分部</td><td class="c t-miss">标准无</td><td class="dim">—</td><td class="dim">厂商扩展</td><td>全为 1(7 / 32 条)</td></tr>
<tr><td class="c">13</td><td>WorkElement 清单项目</td><td class="c t-miss">标准无</td><td class="dim">—</td><td class="dim">厂商扩展</td><td>全为 1(10 / 38 条)</td></tr>
<tr><td class="c">14</td><td>UnitWorksPreliminaryWorkElement / PreliminaryWorkElement 措施项目</td><td class="c t-miss">标准无</td><td class="dim">—</td><td class="dim">厂商扩展(导出器写死)</td><td>全为 1(810+82 / 96+5 条)</td></tr>
<tr><td class="c">15</td><td>LabourMaterialsEquipmentsMachinesElement 工料机含量明细</td><td class="c">4.1.25</td><td class="dim">无 Kind</td><td class="dim">—</td><td>0 条(4 个属性里没有 Kind)</td></tr>
</tbody>
</table>
<p><b>对本系统的直接含义:</b></p>
<ul>
<li>「工料机类型」这 9 个值列<b>只属于工料机汇总这个锚定行</b>——现在的做法正确,不要复制到别的页。</li>
<li>将来建<b>费用汇总页</b>时,那 2 个值列必须叫「<b>汇总条目 / 不汇总条目</b>」,不能复用「人工 / 材料 / 其他」,
否则两页看着一样、含义完全不同。</li>
<li>设备费、预备费如要建库,分别用「类型(国内/国外设备)」「费用类型(基本/价差预备费)」独立命名。</li>
<li>第 5 行那处两家不一致,属于<b>不可靠字段</b>:导入时按 <span class="mono">Number</span> 段数+<span class="mono">Name</span> 是否以"其中"开头判定,别信 Kind。</li>
</ul>
<h2>4 命名规范(以后建列照这个来)</h2>
<div class="card">
<ol>
<li><b>属性列=标准的中文解释原词</b>。不用同义词、不用自造词:<span class="mono">NoTaxPrice</span>→除税编制价(不是"除税价");
<span class="mono">TaxRate</span>→除税率(不是"税率");<span class="mono">Supplier</span>→厂家(不是"供应商");
<span class="mono">Character</span>→质量要求(不是"特征")。</li>
<li><b>值列=枚举标签</b>(一个枚举值一列,绿色可勾选):人工/材料/机械…;乙供/甲供/甲招乙供。</li>
<li><b>一个锚定行一个名称</b>:同一个属性名出现在两个锚定行时,必须加限定词区分——
汇总的 <span class="mono">Remark</span>=<b>汇总备注</b>,含量明细的 <span class="mono">Remark</span>=<b>组成备注</b>;
汇总的 <span class="mono">Number</span>=<b>工料机编码</b>,含量明细的 <span class="mono">Number</span>=<b>引用编码</b>。</li>
<li><b>标准外属性(易达/广联达私有)照收,但名字里能看出"表达式/来源"性质</b>:除税价表达式、含税价表达式、数量表达式、价格来源、损耗率。</li>
<li><b>布尔型属性保留标准名</b>(商品砼 / 主要材料 / 暂估价材料),值填 <span class="mono">TRUE/FALSE</span>;
为使 <span class="mono">ExtKind=4</span> 的值列不与布尔列重名,值列叫「暂估价(扩展)」。</li>
</ol>
</div>
<h2>5 "一层套一层"的界面落地方案</h2>
<h3>5.1 现有模型其实已经能表达层级</h3>
<table>
<thead><tr><th style="width:150px">界面元素</th><th style="width:210px">对应标准里的什么</th><th>说明</th></tr></thead>
<tbody>
<tr><td>左侧目录</td><td>工程结构(项目/单项/单位工程)+ 各类表</td><td>现在只有"表",缺"容器"——见 5.2</td></tr>
<tr><td>标签页</td><td>一种节点类型(如 Summary / Element / UnitWorksSummary)</td><td>一页一类,已实现</td></tr>
<tr><td>锚定行</td><td>该页对应的 XML 元素名</td><td>已实现,cos4 行写的就是元素全名</td></tr>
<tr><td>行(后缀)</td><td>该类型的一个实例(一条工料机、一条费用条目)</td><td>已实现</td></tr>
<tr><td>列</td><td>元素的一个属性</td><td>已按标准改名</td></tr>
<tr><td>值列(绿格)</td><td>枚举属性的某一个取值</td><td>已实现</td></tr>
<tr><td>引用列(编码)</td><td>父子/引用关系</td><td>已有列,缺"可点击跳转"</td></tr>
</tbody>
</table>
<h3>5.2 缺的第一样:目录里要有"工程容器"</h3>
<p>现在目录是平铺的 7 个标签。真实项目里一个项目有多个单项工程、每个单项工程多个单位工程,
而"工料机汇总/清单/定额"都是<b>挂在某个单位工程下面</b>的。建议目录改成两级树:</p>
<div class="cols2">
<div class="wire">
<div class="top">现在:平铺标签</div>
<div class="body">
<div class="nav">
<div>基本设置</div>
<div>单位工程费用汇总</div>
<div>工料机汇总</div>
<div>工料机含量明细</div>
<div>分部分项清单</div>
<div>分部分项定额</div>
<div>措施项目清单</div>
<div>措施项目定额</div>
</div>
<div class="main dim">多单位工程时无法区分"这是哪个单位工程的数据"</div>
</div>
</div>
<div class="wire">
<div class="top">建议:结构容器 + 表</div>
<div class="body">
<div class="nav">
<div>▾ 导出骨架(项目)</div>
<div class="ind1">▾ 单项工程一</div>
<div class="ind1"> ▾ 单位工程 001</div>
<div class="ind1">  <div class="on">费用汇总</div></div>
<div class="ind1">  工料机汇总</div>
<div class="ind1">  工料机含量明细</div>
<div class="ind1">  分部分项清单</div>
<div class="ind1">  措施项目清单</div>
</div>
<div class="main dim">点容器=切上下文;点表=看该单位工程的那张表</div>
</div>
</div>
</div>
<p class="sub">实现成本低:结构节点就是"标签页 + 父标签 id",现有 <span class="mono">tabs</span> 表加一列 <span class="mono">parent_id</span> 与 <span class="mono">node_kind</span>(项目/单项/单位/表),目录渲染本来就是树形递归。</p>
<h3>5.3 缺的第二样:表格里的"树形行"(以你贴的费用汇总为例)</h3>
<p>你给的片段是 <span class="mono">UnitWorksSummary</span> → <span class="mono">UnitWorksSummaryGroup</span>(可再嵌套 Group)
→ <span class="mono">UnitWorksSummaryItem</span>。标准里 <b>Group 与 Item 的属性完全相同</b>(7 条):
费用名称 / 计算基数 / 费率 / 金额 / 费用代号 / 汇总类型 / 备注(实测还多一个 <span class="mono">Number</span>=层级编号 1、2.1、3.1…)。</p>
<div class="note">
<b>结论:不要为 Group 和 Item 建两个锚定行</b>(那会出现两套一模一样的列,违反"列要唯一可读")。
正确做法是<b>一个锚定行</b> <span class="mono">UnitWorksSummaryItem</span> + 一个「汇总类型」值列区分 Group(1) / Item(2),
再用「层级编号」的点分结构自动生成缩进与折叠。
</div>
<div class="wire" style="margin:10px 0">
<div class="top">费用汇总页建议的样子(行首缩进由编号 2 → 2.1 自动推导)</div>
<div class="main">
<div class="row"><span class="cell h">序号</span><span class="cell h">编号</span><span class="cell h">费用名称</span><span class="cell h">计算基数</span><span class="cell h">费率%</span><span class="cell h">金额(元)</span><span class="cell h">费用代号</span><span class="cell h">汇总类型</span><span class="cell h">备注</span></div>
<div class="row"><span class="cell">1</span><span class="cell">1</span><span class="cell">▸ 分部分项工程费</span><span class="cell">QDF</span><span class="cell">100</span><span class="cell">2,308,910.00</span><span class="cell">QDF</span><span class="cell">1 汇总</span><span class="cell dim">—</span></div>
<div class="row"><span class="cell">2</span><span class="cell">2</span><span class="cell">▾ 措施项目费</span><span class="cell"></span><span class="cell"></span><span class="cell">17,505,031.58</span><span class="cell">CSF</span><span class="cell">1 汇总</span><span class="cell dim">—</span></div>
<div class="row"><span class="cell dim">2.1</span><span class="cell">2.1</span><span class="cell" style="margin-left:18px"> 其中:安全生产措施费</span><span class="cell">AQWMSGF</span><span class="cell">100</span><span class="cell">197,496.40</span><span class="cell">AQWMSGF</span><span class="cell">2 不汇总</span><span class="cell dim">—</span></div>
<div class="row"><span class="cell">3</span><span class="cell">3</span><span class="cell">▾ 其他项目费</span><span class="cell"></span><span class="cell"></span><span class="cell">0.00</span><span class="cell">QTF</span><span class="cell">1 汇总</span><span class="cell dim">—</span></div>
<div class="row"><span class="cell dim">3.1</span><span class="cell">3.1</span><span class="cell" style="margin-left:18px"> 其中:暂列金额</span><span class="cell">ZLF</span><span class="cell">100</span><span class="cell">0.00</span><span class="cell">ZLF</span><span class="cell">2 不汇总</span><span class="cell dim">—</span></div>
<div class="row"><span class="cell">4</span><span class="cell">4</span><span class="cell">增值税</span><span class="cell">QDF+CSF+QTF-ZGGC</span><span class="cell">9</span><span class="cell">1,783,254.74</span><span class="cell">SJ</span><span class="cell">1 汇总</span><span class="cell dim">—</span></div>
<div class="row"><span class="cell">5</span><span class="cell">5</span><span class="cell">工程造价</span><span class="cell">QDF+CSF+QTF+SJ</span><span class="cell">100</span><span class="cell">21,597,196.32</span><span class="cell">ZZJ</span><span class="cell">1 汇总</span><span class="cell dim">—</span></div>
</div>
</div>
<div class="card">
<b>树形行的三条规则</b>
<ol>
<li><b>层级靠编号</b>:编号 2 / 2.1 / 2.1.3 的点分段数=缩进级别;没有编号时退化用"上级编号"列手工指。</li>
<li><b>可折叠</b>:Group 行(汇总类型=1)左侧出三角,点一下收起/展开它的全部子行;折叠状态记在本地,刷新不丢。</li>
<li><b>合计校验</b>:Group 行的金额应=其子行之和(汇总类型=2 的"其中"项不参与合计)。不平时行标红提示——
这条对造价审核非常有用(现在只能靠人眼看)。</li>
</ol>
</div>
<h3>5.4 跨页关联:让"引用"能点、能查、能跳</h3>
<ul>
<li><b>可点击</b>:含量明细的「引用编码」、清单的「清单编码」、定额的「定额编号」做成链接样式,双击跳到目标页并高亮那一行。</li>
<li><b>反查</b>:在工料机汇总某行上点"被谁用",列出所有引用它的含量明细/定额(标准注 1 要求编码在项目内唯一,正好作为主键)。</li>
<li><b>面包屑</b>:表格上方显示 <span class="mono">项目 › 单项工程一 › 单位工程 001 › 工料机汇总</span>,任何时候都知道自己在哪一层。</li>
<li><b>校验</b>:导入时检查"含量明细引用的编码是否存在"、"编码是否唯一",不通过的列出来,不静默丢弃。</li>
</ul>
<h3>5.5 建议的落地顺序(每步都能单独验收)</h3>
<table>
<thead><tr><th style="width:56px">步骤</th><th style="width:210px">做什么</th><th>验收标准</th></tr></thead>
<tbody>
<tr><td class="c">S1</td><td>补齐标准缺的 4 个属性列</td><td>工料机汇总加「风险系数 / 基本价格指数 / 现行价格指数」,含量明细加「不计价材料」;空列不报错</td></tr>
<tr><td class="c">S2</td><td>费用汇总页建列 + 树形行</td><td>按 §5.3 的 9 列建好;编号 2.1 能自动缩进、Group 能折叠、合计不平标红</td></tr>
<tr><td class="c">S3</td><td>目录升级为结构树</td><td>项目 → 单项 → 单位 → 表 四级;切换单位工程时各表数据互不串</td></tr>
<tr><td class="c">S4</td><td>引用跳转 + 面包屑 + 导入校验</td><td>双击引用编码能跳;导入两份样例文件零报错,缺失属性留空并列出差异</td></tr>
</tbody>
</table>
<h2>6 待办 / 需要你确认的事</h2>
<div class="card">
<ol>
<li><span class="tag t-ok">已确认</span> <b>Kind 编号</b>:用 COS4 那套(1=人工、2=材料、3=机械、4=主材、5=设备、6=配合比、7=机械台班、8=定额材料、15=其他),
已核实与两家真实文件一致,§3.4 给了三重证据。<b>不改</b>。</li>
<li><b>要不要补 4 个列?</b> 风险系数 ProviderRate、基本价格指数 BasicPrice、现行价格指数 CurrentPrice(工料机汇总)
+ 不计价材料 NOCost(含量明细)。两家导出都不给值,建了是空列,但对齐标准、以后导出/对接要用。</li>
<li><b>费用汇总页按 §5.3 建吗?</b> 一个锚定行 + 汇总类型值列 + 编号缩进折叠。若你更想"Group/Item 各一个锚定行",我按那个做(列名会重复,需要加限定词)。</li>
</ol>
</div>
<footer>
依据文件:《建设工程造价数据交换标准》(征求意见稿)(本机原文转换)/1易达导出骨架.cos4/广联达导出最新架子.COS4。
标准表格原文见 表 4.1.1、4.1.23、4.1.24-1、4.1.25、4.2.1-1、4.2.2-2、4.2.2-3。本页为长期备查文档,未改动任何业务数据。
</footer>
</div>
</body>
</html>