From 6f36b2f494bd588d1b3cb7066f69274ec9ef2dc4 Mon Sep 17 00:00:00 2001 From: lianjianwei2024 <168657369+lianjianwei2024@users.noreply.github.com> Date: Wed, 21 Oct 2026 20:21:51 +0800 Subject: [PATCH] =?UTF-8?q?feat(costreview):=20=E8=AF=A2=E4=BB=B7=E9=99=84?= =?UTF-8?q?=E4=BB=B6=E6=94=AF=E6=8C=81=E6=B8=85=E5=8D=95=E7=BB=91=E5=AE=9A?= =?UTF-8?q?=E5=B9=B6=E6=96=B0=E5=A2=9E=E9=A1=B9=E7=9B=AE=E7=AD=9B=E9=80=89?= =?UTF-8?q?=E3=80=81=E5=8A=A8=E6=80=81=E6=98=8E=E7=BB=86=E6=A0=87=E7=AD=BE?= =?UTF-8?q?=E4=B8=8E=E8=A1=8C=E7=BB=93=E6=9E=84=E7=BB=9F=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AGENTS.md | 1 + CostReview/app/core/match.py | 27 +- CostReview/app/server/api_server.py | 387 ++++++++++++++++---- CostReview/app/store/schema.sql | 10 + CostReview/app/tests/test_api_p1.py | 10 + CostReview/app/tests/test_lme_price.py | 31 +- CostReview/app/ui/admin.html | 480 ++++++++++++++++++------- CostReview/app/ui/common.js | 85 +++-- CostReview/app/ui/sessions.html | 2 +- CostReview/app/ui/workbench.html | 359 ++++++++++++++---- test/界面体检/pages_checks.py | 30 +- test/界面体检/run.py | 18 +- test/界面体检/功能清单(主人填写).md | 24 +- test/界面体检/清浏览器缓存.py | 52 +++ test/界面体检/版本存档/manifest.json | 4 +- test/界面体检/版本存档/上一版.md | 24 +- test/界面体检/版本存档/差异.md | 27 +- test/界面体检/页面清单.json | 2 +- 决策台账.md | 256 +++++++++++++ 决策台账索引.md | 24 +- 20 files changed, 1521 insertions(+), 332 deletions(-) create mode 100644 test/界面体检/清浏览器缓存.py diff --git a/AGENTS.md b/AGENTS.md index deabdb2..4047e1e 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -30,6 +30,7 @@ 3. **批量改文件用行级手术**,禁用跨行正则替换;落盘后回读打印修改处自检。 4. **排查/测试产生的批次、会话、临时文件,收尾时自己清理**;只删自己建的,主人的数据绝不碰。 5. 采纳/新增内容的填空三分类:**有值填值、没算留空、别人的数据擦掉**;架子(结构)严格照被导出文件自己的原生块克隆,不发明、不清零别人有的结构。 +6. **开发阶段不做存量兼容**(2026-10-20 主人定):软件还在开发期,主人定了新口径就直接按新口径实现,**不为存量旧数据/旧格式写识别、迁移或双轨兼容代码**;旧数据等被再次操作时自然被新口径覆盖即可。红线不变:不碰主人的数据、不做破坏性清理。 ## 省 token 铁律(2026-10-20 主人授权) diff --git a/CostReview/app/core/match.py b/CostReview/app/core/match.py index 2b3ebee..d2174f9 100644 --- a/CostReview/app/core/match.py +++ b/CostReview/app/core/match.py @@ -172,7 +172,7 @@ def sim_weighted(qname, hname, qattr, hattr): return 0.7 * jaccard(qname, hname) + 0.3 * a -def _filters(kinds, units, classes, prefix="bt", self_src=None, area=None, orgs=None): +def _filters(kinds, units, classes, prefix="bt", self_src=None, area=None, orgs=None, projs=None): """生成批次级筛选 SQL(默认全选=不筛) self_src:被审工程的源文件名 —— 同一个文件若也在历史库里,排除掉(避免自己跟自己比) area:地区前缀列表 [(省, 市, 区/县), ...](2026-09-29 树形多选后改成这样) @@ -182,6 +182,8 @@ def _filters(kinds, units, classes, prefix="bt", self_src=None, area=None, orgs= orgs:单位(2026-10-08 主人定,工料机比对专用):建设单位 ∪ 发布单位 **跨来源联查**, 一批名字同时匹配 BulidUnit(工程批次)OR x_publisher(价格批次); 工程批次 x_publisher 恒空、价格批次 BulidUnit 恒空,OR 起来天然各走各的。 + projs:项目名称(决策 141,2026-10-20,主人定):按批次项目名 bt.Name 精确匹配(IN), + 与 units 同款;比对/检索两条路径、清单/工料机两侧全部透传。 """ w, args = ["%s.x_enabled=1" % prefix], [] if area: @@ -212,6 +214,9 @@ def _filters(kinds, units, classes, prefix="bt", self_src=None, area=None, orgs= w.append("(%s.BulidUnit IN (%s) OR %s.x_publisher IN (%s))" % (prefix, ",".join("?" * len(orgs)), prefix, ",".join("?" * len(orgs)))) args += list(orgs) + list(orgs) + if projs: + w.append("%s.Name IN (%s)" % (prefix, ",".join("?" * len(projs)))) + args += list(projs) if classes: w.append("p.Class IN (%s)" % ",".join("?" * len(classes))) args += list(classes) @@ -379,11 +384,11 @@ def _region3(p, c, d3): return "/".join(x for x in (p, c, d3) if x) or None -def match_bill(hist, row, base, kinds, units, classes, limit=20, srcs=None, pfrom=None, pto=None, self_name=None, self_src=None, area=None): +def match_bill(hist, row, base, kinds, units, classes, limit=20, srcs=None, pfrom=None, pto=None, self_name=None, self_src=None, area=None, projs=None): bf, bt = span(base) # 基准期次:单月 int 或 (起, 止) 区间 """row: sqlite Row of s_bills""" c = hist.cursor() - w, args = _filters(kinds, units, [], self_src=self_src, area=area) # classes 只对价格库有意义,清单比对不筛目录 + w, args = _filters(kinds, units, [], self_src=self_src, area=area, projs=projs) # classes 只对价格库有意义,清单比对不筛目录 out, seen_ids, qn = [], set(), norm_match(row["Name"]) # L0 精确:编码+名称+单位(b.id 带回 → 前端展开定额 / 右栏「定额编码·名称」用)。 # 2026-10-10 决策 27:哈希里的编码只取前 9 位(后 3 位是项目内顺序码,没有对比意义), @@ -465,7 +470,7 @@ def match_bill(hist, row, base, kinds, units, classes, limit=20, srcs=None, pfro return res[:limit] -def hist_search(hist, kinds, units, area, pfrom, pto, kw, limit=200, self_name=None, self_src=None, page=1, stop=None): +def hist_search(hist, kinds, units, area, pfrom, pto, kw, limit=200, self_name=None, self_src=None, page=1, stop=None, projs=None): """独立检索(2026-10-08 主人定第 4 轮 B 方案):跨**全部入库项目**(kind='project')按 条件+关键词 直查清单库,与工作台选中的行无关(主人:"搜索条件高于点选清单")。 行结构与 match_bill() 完全一致 —— 前端 renderHist / 右栏 / ± 展开零改动复用,差异只有: @@ -477,7 +482,7 @@ def hist_search(hist, kinds, units, area, pfrom, pto, kw, limit=200, self_name=N 或项目名相同。 page:分页(2026-10-08 主人定,每页=limit 条,第 N 页 OFFSET (N-1)×limit)。""" c = hist.cursor() - cond, args = _filters(kinds, units, [], prefix="bt") # 批次级条件(拼好的 SQL 串 + 参数) + cond, args = _filters(kinds, units, [], prefix="bt", projs=projs) # 批次级条件(拼好的 SQL 串 + 参数) extra = [] nm = (self_name or "").strip() src = (self_src or "").strip() @@ -535,7 +540,7 @@ def hist_search(hist, kinds, units, area, pfrom, pto, kw, limit=200, self_name=N def hist_search_lme(hist, orgs=None, area=None, pfrom=None, pto=None, kw="", pmin=None, pmax=None, srcs=None, limit=200, self_name=None, self_src=None, page=1, att="all", kinds=None, - stop=None): + stop=None, projs=None): """独立检索 · 工料机版(2026-10-08 主人定):跨全部入库项目的**工料机**(lmes, kind='project') + 信息价/市场价明细(prices),条件+关键词直查,与工作台选中的行无关。 工料机标签的关键字查询走这里(hist_search 查的是清单库,工料机标签不适用)。 @@ -550,8 +555,8 @@ def hist_search_lme(hist, orgs=None, area=None, pfrom=None, pto=None, kw="", pmi srcs = srcs or ["project", "info", "market"] # kinds=单价类型,只对工程来源生效(价格批次 FileKind 恒空,一传就整片剔除) # → 工程/价格两个分支各拼各的 cond,cargs 分别跟各自的分支参数走 - cond, cargs = _filters(kinds or [], [], [], prefix="bt", self_src=self_src, area=area, orgs=orgs) - condp, cargsp = _filters([], [], [], prefix="bt", self_src=self_src, area=area, orgs=orgs) + cond, cargs = _filters(kinds or [], [], [], prefix="bt", self_src=self_src, area=area, orgs=orgs, projs=projs) + condp, cargsp = _filters([], [], [], prefix="bt", self_src=self_src, area=area, orgs=orgs, projs=projs) outer, oargs = [], [] nm = (self_name or "").strip() src = (self_src or "").strip() @@ -648,7 +653,7 @@ def hist_search_lme(hist, orgs=None, area=None, pfrom=None, pto=None, kw="", pmi return res -def match_lme(hist, row, base, orgs=None, limit=20, srcs=None, pfrom=None, pto=None, self_name=None, self_src=None, area=None, pmin=None, pmax=None, att="all", kinds=None): +def match_lme(hist, row, base, orgs=None, limit=20, srcs=None, pfrom=None, pto=None, self_name=None, self_src=None, area=None, pmin=None, pmax=None, att="all", kinds=None, projs=None): """工料机:历史工程工料机 + 信息价/市场价(价格库) 2026-10-08 主人定:比对按「名称+规格型号+单位」三件套;筛选 = 来源/单价类型/单位/地区/期次/价格范围/附件。 orgs = 单位跨来源联查(建设单位 OR 发布单位,见 _filters);pmin/pmax = 价格范围(除税单价); @@ -662,7 +667,7 @@ def match_lme(hist, row, base, orgs=None, limit=20, srcs=None, pfrom=None, pto=N c = hist.cursor() out, seen_ids = [], set() # ---- 历史工程工料机 ---- - w, args = _filters(kinds or [], [], [], self_src=self_src, area=area, orgs=orgs) + w, args = _filters(kinds or [], [], [], self_src=self_src, area=area, orgs=orgs, projs=projs) wpr, apr = _price_range("l.NoTaxPrice", pmin, pmax) w = w + " AND " + wpr; args = args + apr res = [] @@ -765,7 +770,7 @@ def match_lme(hist, row, base, orgs=None, limit=20, srcs=None, pfrom=None, pto=N # 单位筛选走 orgs(发布单位),价格范围同样对 p.NoTaxPrice 生效。 # ⚠️ **这里永远不加 lme_list_where**(主人 2026-10-09 明示"永远不能屏蔽信息价/市场价的 # 任何单位")—— 刊物里的台班单价等是正常价格行;搜索对象=项目工料机(过滤后)+价格全量。 - wp, argp = _filters([], [], [], prefix="bt", self_src=self_src, area=area, orgs=orgs) + wp, argp = _filters([], [], [], prefix="bt", self_src=self_src, area=area, orgs=orgs, projs=projs) wpp, app = _price_range("p.NoTaxPrice", pmin, pmax) wp = wp + " AND " + wpp; argp = argp + app if pk: diff --git a/CostReview/app/server/api_server.py b/CostReview/app/server/api_server.py index 5faf7a0..a44563d 100644 --- a/CostReview/app/server/api_server.py +++ b/CostReview/app/server/api_server.py @@ -646,7 +646,8 @@ def api_inq_list(con, bid): if not ok: return {"ok": False, "msg": msg} rows = con.execute("""SELECT f.id, f.original_name, f.size, f.ext, f.uploaded_at, - (SELECT COUNT(*) FROM lme_attach a WHERE a.file_id=f.id) AS n + (SELECT COUNT(*) FROM lme_attach a WHERE a.file_id=f.id) + + (SELECT COUNT(*) FROM bill_attach a WHERE a.file_id=f.id) AS n FROM inquiry_files f WHERE f.batch_id=? ORDER BY f.id""", (bid,)).fetchall() total = con.execute("SELECT COUNT(*) FROM lme_attach WHERE batch_id=?", (bid,)).fetchone()[0] return {"ok": True, "total_bound": total, @@ -687,64 +688,114 @@ def api_inq_upload(con, bid, body): def api_inq_bind(con, bid, body): - """把选中的工料机绑到某个附件。 + """把选中的工料机/清单绑到某个附件(决策 152:清单也能绑,同 lme_attach 口径)。 - ★ 允许改绑:lme_id 是主键,INSERT OR REPLACE 冲突即覆盖 —— 覆盖即改绑, + ★ 允许改绑:lme_id/bill_id 是主键,INSERT OR REPLACE 冲突即覆盖 —— 覆盖即改绑, 不需要先解绑。返回里带着「从哪个附件改过来的、几条」,前端据此做二次确认文案。 + body: {file_id, lme_ids?: [...], bill_ids?: [...]} —— 两类至少给一类。 """ ok, msg = _inq_guard(con, bid) if not ok: return {"ok": False, "msg": msg} fid = int(body.get("file_id") or 0) - ids = [int(x) for x in (body.get("lme_ids") or [])] + lme_ids = [int(x) for x in (body.get("lme_ids") or [])] + bill_ids = [int(x) for x in (body.get("bill_ids") or [])] if not fid: return {"ok": False, "msg": "请先在左边选中一个附件"} - if not ids: - return {"ok": False, "msg": "还没有勾选工料机"} + if not lme_ids and not bill_ids: + return {"ok": False, "msg": "还没有勾选工料机/清单"} row = con.execute("SELECT original_name FROM inquiry_files WHERE id=? AND batch_id=?", (fid, bid)).fetchone() if not row: return {"ok": False, "msg": "附件不存在(可能已被删除)"} cur = con.cursor() - # 只接受确实属于本项目的工料机(防越权:传别项目的 lme_id 也绑不上) - q = "SELECT id FROM lmes WHERE batch_id=? AND id IN (%s)" % ",".join("?" * len(ids)) - valid = [r[0] for r in cur.execute(q, [bid] + ids)] - if not valid: - return {"ok": False, "msg": "勾选的工料机不属于这个项目"} - # 改绑统计:这些行原本绑在哪些附件上 - moved = {} - for lme_id, old_name in cur.execute( - """SELECT a.lme_id, f.original_name FROM lme_attach a - JOIN inquiry_files f ON f.id=a.file_id - WHERE a.lme_id IN (%s)""" % ",".join("?" * len(valid)), valid): - moved[old_name] = moved.get(old_name, 0) + 1 - for lme_id in valid: - cur.execute("INSERT OR REPLACE INTO lme_attach(lme_id, batch_id, file_id) VALUES(?,?,?)", - (lme_id, bid, fid)) - con.commit() - n = len(valid) + n = 0 hint = "" - if moved: - hint = "(其中 %s)" % "、".join( - "%d 条从《%s》改绑过来" % (c, (k or "").strip()[:24]) for k, c in moved.items()) - return {"ok": True, "n": n, "moved": moved, - "msg": "已把 %d 条工料机绑定到《%s》%s" % (n, (row[0] or "")[:40], hint)} + if lme_ids: + # 只接受确实属于本项目的工料机(防越权:传别项目的 lme_id 也绑不上) + q = "SELECT id FROM lmes WHERE batch_id=? AND id IN (%s)" % ",".join("?" * len(lme_ids)) + valid = [r[0] for r in cur.execute(q, [bid] + lme_ids)] + if not valid: + return {"ok": False, "msg": "勾选的工料机不属于这个项目"} + # 改绑统计:这些行原本绑在哪些附件上 + moved = {} + for lme_id, old_name in cur.execute( + """SELECT a.lme_id, f.original_name FROM lme_attach a + JOIN inquiry_files f ON f.id=a.file_id + WHERE a.lme_id IN (%s)""" % ",".join("?" * len(valid)), valid): + moved[old_name] = moved.get(old_name, 0) + 1 + for lme_id in valid: + cur.execute("INSERT OR REPLACE INTO lme_attach(lme_id, batch_id, file_id) VALUES(?,?,?)", + (lme_id, bid, fid)) + n += len(valid) + if moved: + hint = "(其中 %s)" % "、".join( + "%d 条从《%s》改绑过来" % (c, (k or "").strip()[:24]) for k, c in moved.items()) + if bill_ids: + q = "SELECT id FROM bills WHERE batch_id=? AND id IN (%s)" % ",".join("?" * len(bill_ids)) + valid = [r[0] for r in cur.execute(q, [bid] + bill_ids)] + if not valid and not lme_ids: + return {"ok": False, "msg": "勾选的清单不属于这个项目"} + moved = {} + for bill_id, old_name in cur.execute( + """SELECT a.bill_id, f.original_name FROM bill_attach a + JOIN inquiry_files f ON f.id=a.file_id + WHERE a.bill_id IN (%s)""" % ",".join("?" * len(valid)), valid): + moved[old_name] = moved.get(old_name, 0) + 1 + for bill_id in valid: + cur.execute("INSERT OR REPLACE INTO bill_attach(bill_id, batch_id, file_id) VALUES(?,?,?)", + (bill_id, bid, fid)) + n += len(valid) + if moved: + hint += ("%s%s" % (";" if hint else "", "、".join( + "%d 条清单从《%s》改绑过来" % (c, (k or "").strip()[:24]) for k, c in moved.items()))) + con.commit() + what = "工料机" if lme_ids else "清单" + return {"ok": True, "n": n, "msg": "已把 %d 条%s绑定到《%s》%s" % (n, what, (row[0] or "")[:40], hint)} def api_inq_unbind(con, bid, body): - """解绑:把选中的工料机从附件上摘下来(附件本身保留)""" + """解绑:把选中的工料机/清单从附件上摘下来(附件本身保留)""" ok, msg = _inq_guard(con, bid) if not ok: return {"ok": False, "msg": msg} - ids = [int(x) for x in (body.get("lme_ids") or [])] - if not ids: - return {"ok": False, "msg": "还没有勾选工料机"} + lme_ids = [int(x) for x in (body.get("lme_ids") or [])] + bill_ids = [int(x) for x in (body.get("bill_ids") or [])] + if not lme_ids and not bill_ids: + return {"ok": False, "msg": "还没有勾选工料机/清单"} cur = con.cursor() - cur.execute("DELETE FROM lme_attach WHERE batch_id=? AND lme_id IN (%s)" - % ",".join("?" * len(ids)), [bid] + ids) - n = cur.rowcount + n = 0 + if lme_ids: + cur.execute("DELETE FROM lme_attach WHERE batch_id=? AND lme_id IN (%s)" + % ",".join("?" * len(lme_ids)), [bid] + lme_ids) + n += cur.rowcount + if bill_ids: + cur.execute("DELETE FROM bill_attach WHERE batch_id=? AND bill_id IN (%s)" + % ",".join("?" * len(bill_ids)), [bid] + bill_ids) + n += cur.rowcount con.commit() - return {"ok": True, "n": n, "msg": "已解绑 %d 条工料机" % n} + return {"ok": True, "n": n, "msg": "已解绑 %d 条" % n} + + +def api_inq_bills(con, bid): + """该项目的全部清单 + 当前绑定状态(决策 152 类似清单页签用)。 + + 字段与后台「类似清单」结果行一致:编码/名称/项目特征/单位/工程量/单价/合价; + 不做相似过滤 —— 这里是**本批次自己的全部清单**,勾选绑附件用。""" + ok, msg = _inq_guard(con, bid) + if not ok: + return {"ok": False, "msg": msg} + rows = con.execute("""SELECT b.id, b.Number, b.Name, b.Attr, b.Unit, b.Quantity, b.Price, b.Total, + a.file_id, f.original_name + FROM bills b + LEFT JOIN bill_attach a ON a.bill_id=b.id + LEFT JOIN inquiry_files f ON f.id=a.file_id + WHERE b.batch_id=? ORDER BY b.id""", (bid,)).fetchall() + return {"ok": True, "rows": [ + {"id": r[0], "code": r[1] or "", "name": r[2] or "", "attr": r[3] or "", + "unit": r[4] or "", "qty": r[5], "price": r[6], "total": r[7], + "file_id": r[8], "file_name": r[9] or ""} + for r in rows]} def api_inq_del(con, bid, body): @@ -759,7 +810,9 @@ def api_inq_del(con, bid, body): return {"ok": False, "msg": "附件不存在"} cur = con.cursor() n = cur.execute("SELECT COUNT(*) FROM lme_attach WHERE file_id=?", (fid,)).fetchone()[0] + n += cur.execute("SELECT COUNT(*) FROM bill_attach WHERE file_id=?", (fid,)).fetchone()[0] cur.execute("DELETE FROM lme_attach WHERE file_id=?", (fid,)) + cur.execute("DELETE FROM bill_attach WHERE file_id=?", (fid,)) cur.execute("DELETE FROM inquiry_files WHERE id=?", (fid,)) con.commit() # 同 sha 的别处还在用就不删文件(与价格原件同一套规矩) @@ -1829,18 +1882,22 @@ def _raw_proj(con, T, oid, tab): # sub = 带子级组成的编码集(台班/配合比),前端据此挂 title 提示。 try: _hide = " AND COALESCE(x_merged_hide,0)=0" if T.get("lmemerge") else "" - rows = con.execute("""SELECT id, code, name, spec, unit, kind, qty, ntp, taxrate, taxp + # 决策 147(2026-10-21 主人定):项目级卡与「项目工料机」同码同形 —— 返回 _lme_rows 同形 + # 11 列(id 在首位、备注位 10),前端 renderLme 唯一渲染;不再 rows/ids 分离。 + # 数据集差异保留:此处**不过** LME_LIST_WHERE(全量含台班/配合比),合并隐藏两处同滤。 + rows = con.execute("""SELECT id, code, name, spec, unit, qty, ntp, taxrate, taxp, + kind, %(rm)s AS remark FROM %(lp)s WHERE %(idc)s=?%(hide)s ORDER BY id""" - % {"lp": T["lme_proj"], "idc": T["idcol"], "hide": _hide}, (oid,)).fetchall() + % {"lp": T["lme_proj"], "idc": T["idcol"], "hide": _hide, + "rm": T.get("lme_remark", "NULL")}, (oid,)).fetchall() except Exception: rows = [] # 老库还没建表/没回填:退回旧口径 if rows: - return {"ok": True, "rows": [list(x)[1:] for x in rows], - "ids": [x[0] for x in rows], "sub": _lme_sub_codes(con, T, oid)} + return {"ok": True, "rows": [list(x) for x in rows], "sub": _lme_sub_codes(con, T, oid)} # 老库回退支:lmes 可能没有 TaxRate 列 —— 仿 _norm_res 的 PRAGMA 探测,缺列恒补 None。 - # 9 列行形与主路一致:6=除税 7=税率 8=含税(TaxRate 插在 TaxPrice 之前)。 + # 决策 147:回退支同样 11 列(id/备注补 NULL),行形与主路一致。 has_tax = any(x[1] == "TaxRate" for x in con.execute("PRAGMA table_info(%s)" % T["lmes"])) - rows = con.execute("""SELECT Number, Name, Specification, Unit, Kind, Quantity, NoTaxPrice, %(txr)s TaxPrice + rows = con.execute("""SELECT NULL, Number, Name, Specification, Unit, Quantity, NoTaxPrice, %(txr)s TaxPrice, Kind, NULL FROM %(lm)s WHERE %(idc)s=? AND NoTaxPrice IS NOT NULL ORDER BY Quantity DESC LIMIT 800""" % {"lm": T["lmes"], "idc": T["idcol"], @@ -3291,17 +3348,41 @@ def api_bill_adopt(sc, hc, body): sid = int(body.get("session_id", 0) or 0) bid = int(body.get("bill_id", 0) or 0) src_id = int(body.get("src_bill_id", 0) or 0) + src_self = int(body.get("src_self_bill_id", 0) or 0) # 决策 158:来源=本会话清单(范围=是) sb = sc.execute("SELECT id, session_id, uw_id, x_new, x_tdel FROM s_bills WHERE id=? AND session_id=?", (bid, sid)).fetchone() if not sb: return {"ok": False, "msg": "清单不存在(可能已被删除,请刷新)"} if sb["x_tdel"]: return {"ok": False, "msg": "临时删除状态不可以采纳(规格 9.2)——先取消临时删除"} - bb = hc.execute("SELECT id, Number, Name, Attr, Unit, Price, Quantity FROM bills WHERE id=?", (src_id,)).fetchone() - if not bb: - return {"ok": False, "msg": "入库项目清单不存在(批次可能已删除)"} - bnorms = hc.execute("""SELECT id, Number, Name, Unit, Quantity, Price, Total, x_qty_coef, x_adjust - FROM norms WHERE bill_id=? ORDER BY id""", (src_id,)).fetchall() + if src_self: + if src_self == bid: + return {"ok": False, "msg": "不能采纳清单自己"} + bb = sc.execute("SELECT id, Number, Name, Attr, Unit, Price, Quantity FROM s_bills WHERE id=? AND session_id=?", + (src_self, sid)).fetchone() + if not bb: + return {"ok": False, "msg": "本工程来源清单不存在(可能已被删除,请刷新)"} + bnorms = sc.execute("""SELECT id, Number, Name, Unit, Quantity, Price, Total, + NULL AS x_qty_coef, x_adjust, qty_expr + FROM s_norms WHERE bill_id=? AND (x_tdel IS NULL OR x_tdel=0) ORDER BY id""", + (src_self,)).fetchall() + else: + bb = hc.execute("SELECT id, Number, Name, Attr, Unit, Price, Quantity FROM bills WHERE id=?", (src_id,)).fetchone() + if not bb: + return {"ok": False, "msg": "入库项目清单不存在(批次可能已删除)"} + bnorms = hc.execute("""SELECT id, Number, Name, Unit, Quantity, Price, Total, x_qty_coef, x_adjust + FROM norms WHERE bill_id=? ORDER BY id""", (src_id,)).fetchall() + + def _norm_expr(nn): + # 批次来源:GCL×系数公式现算(规格 19);会话来源:qty_expr 原样带(公式本就按 GCL 走, + # 换到目标清单后随目标工程量求值,语义同款) + return nn["qty_expr"] if src_self else _gcl_coef_expr(nn["Quantity"], bb["Quantity"], nn["x_qty_coef"], nn["Unit"]) + + def _norm_res(nn_id): + if src_self: + return sc.execute("SELECT res_code, qty, express FROM s_norm_res WHERE norm_id=? ORDER BY id", (nn_id,)) + return hc.execute("SELECT res_code, qty, express FROM norm_res WHERE norm_id=? ORDER BY id", (nn_id,)) + is_new = bool(sb["x_new"]) # 规格 19(2026-10-17 主人定·采纳逻辑变化):采纳定额工程量默认公式 = **GCL×系数**, # 系数 = 历史定额量 ÷ 历史清单量(例:历史清单量 500、定额量 300 → GCL*0.6000)—— @@ -3320,11 +3401,10 @@ def api_bill_adopt(sc, hc, body): cur = sc.execute("""INSERT INTO s_norms(bill_id, Number, Name, Unit, Quantity, Price, Total, x_adopt, x_src_norm_id, qty_expr, x_adjust) VALUES(?,?,?,?,NULL,?,NULL,1,?,?,?)""", - (bid, nn["Number"], nn["Name"], nn["Unit"], nn["Price"], nn["id"], - _gcl_coef_expr(nn["Quantity"], bb["Quantity"], nn["x_qty_coef"], nn["Unit"]), - nn["x_adjust"])) + (bid, nn["Number"], nn["Name"], nn["Unit"], nn["Price"], + None if src_self else nn["id"], _norm_expr(nn), nn["x_adjust"])) adopted_norm_ids.append(cur.lastrowid) - for rr in hc.execute("SELECT res_code, qty, express FROM norm_res WHERE norm_id=? ORDER BY id", (nn["id"],)): + for rr in _norm_res(nn["id"]): sc.execute("INSERT INTO s_norm_res(norm_id, res_code, qty, express) VALUES(?,?,?,?)", (cur.lastrowid, rr["res_code"], rr["qty"], rr["express"])) else: @@ -3337,18 +3417,21 @@ def api_bill_adopt(sc, hc, body): cur = sc.execute("""INSERT INTO s_norms(bill_id, Number, Name, Unit, Quantity, Price, Total, x_adopt, x_src_norm_id, qty_expr, x_adjust) VALUES(?,?,?,?,NULL,?,NULL,1,?,?,?)""", - (bid, nn["Number"], nn["Name"], nn["Unit"], nn["Price"], nn["id"], - _gcl_coef_expr(nn["Quantity"], bb["Quantity"], nn["x_qty_coef"], nn["Unit"]), - nn["x_adjust"])) + (bid, nn["Number"], nn["Name"], nn["Unit"], nn["Price"], + None if src_self else nn["id"], _norm_expr(nn), nn["x_adjust"])) adopted_norm_ids.append(cur.lastrowid) - for rr in hc.execute("SELECT res_code, qty, express FROM norm_res WHERE norm_id=? ORDER BY id", (nn["id"],)): + for rr in _norm_res(nn["id"]): sc.execute("INSERT INTO s_norm_res(norm_id, res_code, qty, express) VALUES(?,?,?,?)", (cur.lastrowid, rr["res_code"], rr["qty"], rr["express"])) bqty = sc.execute("SELECT Quantity FROM s_bills WHERE id=?", (bid,)).fetchone()["Quantity"] btotal = round((float(bqty) if bqty is not None else 0.0) * (float(new_price) if new_price is not None else 0.0), 2) sc.execute("UPDATE s_bills SET Price=?, Total=?, x_adopt=1 WHERE id=?", (new_price, btotal, bid)) # 决策 108:消耗量随名称/规格/单位匹配结果改码(逐行读现值再映射,防 A→B→C 链式误改) - n_sum, code_map = _adopt_summary_rows(sc, hc, sid, sb["uw_id"], src_id) + # 会话来源跳过——来源消耗量的编码本就是本地码,无需重配(决策 158) + if src_self: + n_sum, code_map = 0, {} + else: + n_sum, code_map = _adopt_summary_rows(sc, hc, sid, sb["uw_id"], src_id) n_recode = 0 for nid in adopted_norm_ids: for rr in sc.execute("SELECT id, res_code FROM s_norm_res WHERE norm_id=?", (nid,)).fetchall(): @@ -3628,10 +3711,14 @@ def api_lme_merge(sc, body): rid = int(r.get("id", 0) or 0) except (TypeError, ValueError): continue + _ntp = _num_or_none(r.get("ntp")) + _rate = _num_or_none(r.get("taxrate")) + _taxp = _num_or_none(r.get("taxp")) + if _ntp is not None and _rate is not None: # 决策 146:等式恒成立(除税方向复核,同 api_lme_price) + _taxp = round(_ntp * (1 + _rate / 100.0) + 1e-9, 2) sc.execute("""UPDATE s_lme_proj SET code=?, ntp=?, taxrate=?, taxp=? WHERE session_id=? AND id=? AND COALESCE(x_merged_hide,0)=0""", - (r.get("code"), _num_or_none(r.get("ntp")), _num_or_none(r.get("taxrate")), - _num_or_none(r.get("taxp")), sid, rid)) + (r.get("code"), _ntp, _rate, _taxp, sid, rid)) kept += 1 row = sc.execute("SELECT code FROM s_lme_proj WHERE id=?", (rid,)).fetchone() if row and not keep_code: @@ -3987,14 +4074,15 @@ def api_search(body): pmin=_num_or_none(body.get("pmin")), pmax=_num_or_none(body.get("pmax")), att=body.get("att") or "all", - kinds=body.get("file_kinds") or []) + kinds=body.get("file_kinds") or [], + projs=body.get("projs") or []) else: res = match.match_bill(hist, row, base, body.get("file_kinds") or [], body.get("bulid_units") or [], body.get("classes") or [], limit, srcs, pf, pt, None if scope_self else self_name, None if scope_self else self_src, - area) + area, projs=body.get("projs") or []) # 规格 20:本组其他清单的批次记录(bill_id 集合)——组价不一致对比按它过滤 allowed = None if scope_self and members is not None: @@ -4021,6 +4109,23 @@ def api_search(body): # (第 N 组 3 条 → 只显示另外 2 条);别的项目/别的历史记录不展示。 # 工具栏独立检索(/api/hist/search)不受限。被点清单自己的记录亦不在本组集合内。 res = [r for r in res if r.get("bill_id") in allowed] + if typ == "bill" and res: + # 决策 152:清单绑定的询价附件 → 工作台历史对比框可下载(file/file_sha/file_url 同工料机行) + c2 = conn() + try: + m = {} + for bid_, fid_, nm_, sha_ in c2.execute( + """SELECT a.bill_id, f.id, f.original_name, f.sha256 FROM bill_attach a + JOIN inquiry_files f ON f.id=a.file_id WHERE a.bill_id IN (%s)""" + % ",".join("?" * len(res)), [r.get("bill_id") for r in res]): + m[bid_] = (fid_, nm_, sha_) + finally: + c2.close() + for r in res: + hit = m.get(r.get("bill_id")) + if hit: + r["file"], r["file_sha"] = hit[1] or "", hit[2] or "" + r["file_url"] = "/api/admin/inq/file/%d" % hit[0] return {"ok": True, "base_period": match.ym(pf) + ("~" + match.ym(pt) if pt != pf else ""), "rows": res, "total": len(res)} @@ -4035,6 +4140,154 @@ def _num_or_none(v): return None +def api_self_search(body): + """范围=是(决策 158,2026-10-21 主人定):「本项目」下拉是数据第一关—— + 是=数据流走 session 库(本工程自己的行,本端点);否=走批次库(/api/search、/api/hist/search, + 排除自己,现行规则)。关键字「查询」路径同样跟随下拉。 + type='bill':本工程其他清单(跨单位工程同名/近似;scope='self_group'=组价不一致:会话内 + 本组其他清单——规格 20 的组定义直读会话,不再绕批次库);type='lme':本工程自己的工料机 + (s_lmes 各单位明细行)。 + 行结构与 /api/search 一致(renderHist/右栏/±/采纳零改动复用),差异: + · src='本工程'、proj=单位工程名(工料机行无单位归属,恒『本工程』)、period=本工程基准期次; + · 清单行带 norms=6+2 列(同 _bill_norms 形状,右栏/±/悬停直读,不走 histNorms); + · self_bill_id=会话清单 id(采纳走 /api/session/bill/adopt 的 src_self_bill_id 分支)。 + 档位与库内同一套(精确/次精确/字集/模糊,同 match_bill/match_lme 口径); + kw/stop 同库内口径;期次/地区/单位/价格范围等库条件对本工程无意义,不参与。""" + sid = int(body.get("session_id", 0) or 0) + typ = body.get("type", "lme") + rid = int(body.get("row_id", 0) or 0) + limit = min(int(body.get("limit", 200) or 200), 500) + sc = sess.connect() + try: + s = sc.execute("SELECT * FROM sessions WHERE id=?", (sid,)).fetchone() + if not s: + return {"ok": False, "msg": "会话不存在"} + _k = s.keys() + pf = (s["period_from"] if "period_from" in _k else None) or s["base_period_m"] or 0 + pt = (s["period_to"] if "period_to" in _k else None) or pf + period = match.ym(pf) + ("~" + match.ym(pt) if pt != pf else "") + region = match._region3(s["x_province"] if "x_province" in _k else None, + s["x_city"] if "x_city" in _k else None, + s["x_district"] if "x_district" in _k else None) + bunit = (s["bulid_unit"] if "bulid_unit" in _k else None) or "" + sw = _setting_get("global", "match_stopwords") + try: + match.set_stopwords(json.loads(sw)) if sw else match.set_stopwords([]) + except Exception: + match.set_stopwords([]) + stops = match.stop_words(body.get("stop")) + kw = match._kw_fold(body.get("kw") or "") + + def _pass(txts): + hay = match._kw_fold(" ".join(str(t or "") for t in txts)) + if kw and not all(t in hay for t in re.split(r"\s+", kw) if t): + return False + if stops and any(match._kw_fold(w) in hay for w in stops): + return False + return True + + rows = [] + if typ == "bill": + row = sc.execute("SELECT * FROM s_bills WHERE id=? AND session_id=?", (rid, sid)).fetchone() if rid else None + if rid and not row: + return {"ok": False, "msg": "找不到这一行"} + uw_names = {u["id"]: (u["Name"] or "") for u in + sc.execute("SELECT id, Name FROM s_unit_works WHERE session_id=?", (sid,))} + grp = bool(row) and (body.get("scope") == "self_group") and row["x_name_norm"] is not None + if row is None: + cands = sc.execute("SELECT * FROM s_bills WHERE session_id=? ORDER BY id", (sid,)).fetchall() + elif grp: + cands = sc.execute("""SELECT * FROM s_bills WHERE session_id=? AND id<>? + AND x_name_norm IS ? AND x_attr_norm IS ? ORDER BY id""", + (sid, rid, row["x_name_norm"], row["x_attr_norm"])).fetchall() + else: + cands = sc.execute("SELECT * FROM s_bills WHERE session_id=? AND id<>? ORDER BY id", + (sid, rid)).fetchall() + qn = match.norm_match(row["Name"]) if row is not None else None + qattr = match.norm_match(row["Attr"] or "") if row is not None else None + setkey = match.bill_setkey(row["Name"], row["Unit"]) if row is not None else None + pre = match.norm(row["Name"])[:6] if row is not None else None + for b in cands: + if row is None: + rows.append({ + "tier": "检索", "name": b["Name"], "attr": b["Attr"], "unit": b["Unit"], + "price": b["Price"], "period": period, "period_m": pf, "dist": 0, + "sim": None, "src": "本工程", "proj": uw_names.get(b["uw_id"]) or "本工程", + "bunit": bunit, "region": region, "self_bill_id": b["id"], + "norms": [[n["Number"], n["Name"], n["Unit"], n["Quantity"], n["Price"], n["Total"], 0, 0] + for n in sc.execute("""SELECT Number, Name, Unit, Quantity, Price, Total, x_tdel FROM s_norms WHERE bill_id=? AND (x_tdel IS NULL OR x_tdel=0) ORDER BY id""", (b["id"],)).fetchall()], + "file": "", "file_url": ""}) + continue + tier, sim = None, None + j = match.jaccard(qn, match.norm_match(b["Name"])) + if b["x_hash_exact"] and b["x_hash_exact"] == row["x_hash_exact"]: + tier, sim = "精确", 1.0 + elif b["x_hash_semi"] and b["x_hash_semi"] == row["x_hash_semi"] and j >= match.SEMI_NAME_MIN: + tier, sim = "次精确", 1.0 + elif match.bill_setkey(b["Name"], b["Unit"]) == setkey: + tier, sim = "字集", 1.0 + elif (not grp and pre and match.norm(b["Name"]).startswith(pre) + and match.norm(b["Unit"]) == match.norm(row["Unit"])): + simv = match.sim_weighted(qn, match.norm_match(b["Name"]), qattr, + match.norm_match(b["Attr"] or "")) + if simv >= match.SIM_MIN: + tier, sim = "模糊", round(simv, 2) + if tier is None: + continue + norms = [[n["Number"], n["Name"], n["Unit"], n["Quantity"], n["Price"], n["Total"], 0, 0] + for n in sc.execute("""SELECT Number, Name, Unit, Quantity, Price, Total, x_tdel + FROM s_norms WHERE bill_id=? AND (x_tdel IS NULL OR x_tdel=0) + ORDER BY id""", (b["id"],)).fetchall()] + rows.append({ + "tier": tier, "name": b["Name"], "attr": b["Attr"], "unit": b["Unit"], + "price": b["Price"], "period": period, "period_m": pf, "dist": 0, + "sim": sim, "src": "本工程", "proj": uw_names.get(b["uw_id"]) or "本工程", + "bunit": bunit, "region": region, "self_bill_id": b["id"], "norms": norms, + "file": "", "file_url": ""}) + else: + row = sc.execute("SELECT * FROM s_lme_proj WHERE id=? AND session_id=?", (rid, sid)).fetchone() if rid else None + if rid and not row: + return {"ok": False, "msg": "找不到这一行"} + h_e = job.md5(row["name"], row["spec"], row["unit"]) if row is not None else None + h_s = job.md5(row["name"], row["unit"]) if row is not None else None + setk = match.lme_setkey(row["name"], row["spec"], row["unit"]) if row is not None else None + qn = match.norm_match(row["name"]) if row is not None else None + pre = match.norm(row["name"])[:6] if row is not None else None + for l in sc.execute("SELECT * FROM s_lmes WHERE session_id=? ORDER BY id", (sid,)).fetchall(): + if row is None: + rows.append({ + "tier": "检索", "name": l["Name"], "attr": "", "spec": l["Specification"], + "unit": l["Unit"], "price": l["NoTaxPrice"], "tax": l["TaxRate"], + "price_tax": l["TaxPrice"], "note": "", "period": period, "period_m": pf, + "dist": 0, "sim": None, "src": "本工程", "proj": "本工程", "bunit": bunit, + "region": region, "file": "", "file_url": ""}) + continue + tier, sim = None, None + j = match.jaccard(qn, match.norm_match(l["Name"])) + if l["x_hash_exact"] and l["x_hash_exact"] == h_e: + tier, sim = "精确", 1.0 + elif l["x_hash_semi"] and l["x_hash_semi"] == h_s: + tier, sim = "次精确", 1.0 + elif match.lme_setkey(l["Name"], l["Specification"], l["Unit"]) == setk: + tier, sim = "字集", 1.0 + elif pre and match.norm(l["Name"]).startswith(pre) and match.norm(l["Unit"]) == match.norm(row["unit"]): + if j >= match.SIM_MIN: + tier, sim = "模糊", round(j, 2) + if tier is None: + continue + rows.append({ + "tier": tier, "name": l["Name"], "attr": "", "spec": l["Specification"], + "unit": l["Unit"], "price": l["NoTaxPrice"], "tax": l["TaxRate"], + "price_tax": l["TaxPrice"], "note": "", "period": period, "period_m": pf, + "dist": 0, "sim": sim, "src": "本工程", "proj": "本工程", "bunit": bunit, + "region": region, "file": "", "file_url": ""}) + rows = [r for r in rows + if _pass((r.get("name"), r.get("attr"), r.get("spec"), r.get("unit")))] + return {"ok": True, "base_period": period, "rows": rows[:limit], "total": len(rows)} + finally: + sc.close() + + def api_hist_search(body): """独立检索(2026-10-08 主人定 B 方案):条件+关键词 跨全部入库项目 target='bill'(默认)查**清单库**;target='lme'(工料机标签专用,2026-10-08 主人定) @@ -4077,6 +4330,7 @@ def api_hist_search(body): limit=min(int(body.get("limit", 200)), 500), self_name=self_name, self_src=self_src, page=int(body.get("page", 1) or 1), + projs=body.get("projs") or [], stop=match.stop_words(body.get("stop"))) else: res = match.hist_search(hist, @@ -4088,6 +4342,7 @@ def api_hist_search(body): min(int(body.get("limit", 200)), 500), self_name=self_name, self_src=self_src, page=int(body.get("page", 1) or 1), + projs=body.get("projs") or [], stop=match.stop_words(body.get("stop"))) finally: hist.close() @@ -4125,6 +4380,7 @@ def api_delete_batch(con, bid): con.execute("DELETE FROM lme_proj WHERE batch_id=?", (bid,)) con.execute("DELETE FROM lme_uw WHERE batch_id=?", (bid,)) con.execute("DELETE FROM lme_attach WHERE batch_id=?", (bid,)) + con.execute("DELETE FROM bill_attach WHERE batch_id=?", (bid,)) con.execute("DELETE FROM inquiry_files WHERE batch_id=?", (bid,)) con.execute("DELETE FROM unit_works WHERE batch_id=?", (bid,)) con.execute("DELETE FROM sections WHERE batch_id=?", (bid,)) @@ -4213,6 +4469,7 @@ def api_clear_mock(con): con.execute("DELETE FROM lme_proj WHERE batch_id IN (%s)" % ph, part) con.execute("DELETE FROM lme_uw WHERE batch_id IN (%s)" % ph, part) con.execute("DELETE FROM lme_attach WHERE batch_id IN (%s)" % ph, part) + con.execute("DELETE FROM bill_attach WHERE batch_id IN (%s)" % ph, part) con.execute("DELETE FROM inquiry_files WHERE batch_id IN (%s)" % ph, part) con.execute("DELETE FROM unit_works WHERE batch_id IN (%s)" % ph, part) con.execute("DELETE FROM sections WHERE batch_id IN (%s)" % ph, part) @@ -5736,6 +5993,7 @@ def api_filters(): # 2026-10-07 主人定:列表筛选补 单价类型(已有 file_kind)/建设单位/总价区间/发布单位 "bu_rows": _distinct_rows("BulidUnit", "kind='project'"), # 历史项目里出现过的建设单位 "pub_rows": _distinct_rows("x_publisher", "kind<>'project'"), # 信息价/市场价里出现过的发布单位 + "proj_rows": _distinct_rows("Name", "kind='project'"), # 决策 141:项目名称框选项池(历史项目名) } @@ -6123,6 +6381,13 @@ class Handler(SimpleHTTPRequestHandler): return self._json(api_inq_list(c, int(m.group(1)))) finally: c.close() + m = re.match(r"^/api/admin/batch/(\d+)/inq/bills$", p) # 决策 152:类似清单页签 + if m: + c = conn() + try: + return self._json(api_inq_bills(c, int(m.group(1)))) + finally: + c.close() m = re.match(r"^/api/admin/inq/file/(\d+)$", p) # 下载 if m: return self._inq_file(int(m.group(1))) @@ -6221,6 +6486,8 @@ class Handler(SimpleHTTPRequestHandler): return self._json(api_session_delete(body)) if u.path == "/api/search": # 比对:找历史相似项 return self._json(api_search(body)) + if u.path == "/api/self/search": # 范围=是(决策 158):本会话内比对/检索 + return self._json(api_self_search(body)) if u.path == "/api/hist/search": # 独立检索(2026-10-08 B 方案):条件+关键词 跨全部入库项目查清单 return self._json(api_hist_search(body)) if u.path == "/api/session/setting": # 工作台「分组/匹配」设置写入(会话库) diff --git a/CostReview/app/store/schema.sql b/CostReview/app/store/schema.sql index de45ff4..6388034 100644 --- a/CostReview/app/store/schema.sql +++ b/CostReview/app/store/schema.sql @@ -339,6 +339,16 @@ CREATE TABLE IF NOT EXISTS lme_attach( CREATE INDEX IF NOT EXISTS ix_lmeatt_file ON lme_attach(file_id); CREATE INDEX IF NOT EXISTS ix_lmeatt_batch ON lme_attach(batch_id); +-- 清单 ↔ 询价附件 的关联(2026-10-21 决策 152:类似清单页签也能绑附件,同 lme_attach 口径) +-- · 一条清单 → 只一个附件(★ bill_id 作主键,数据库强制);换绑 INSERT OR REPLACE 覆盖。 +CREATE TABLE IF NOT EXISTS bill_attach( + bill_id INTEGER PRIMARY KEY, -- bills.id + batch_id INTEGER NOT NULL, -- 冗余,便于按项目整体清理 + file_id INTEGER NOT NULL +); +CREATE INDEX IF NOT EXISTS ix_bilatt_file ON bill_attach(file_id); +CREATE INDEX IF NOT EXISTS ix_bilatt_batch ON bill_attach(batch_id); + -- =========================================================================== -- 数据源字典(2026-10-06 新增) -- diff --git a/CostReview/app/tests/test_api_p1.py b/CostReview/app/tests/test_api_p1.py index e0cb94b..57db096 100644 --- a/CostReview/app/tests/test_api_p1.py +++ b/CostReview/app/tests/test_api_p1.py @@ -131,6 +131,16 @@ def test_inq_lifecycle(server): assert un["ok"] is True and un["n"] == 1 assert get(server, "/api/admin/batch/%d/inq" % b1)["total_bound"] == 0 post(server, "/api/admin/batch/%d/inq/bind" % b1, {"file_id": fid, "lme_ids": [lme_b1]}) + # 决策 152:清单也能绑附件(bill_attach 同口径)+ /inq/bills 列表 + 附件角标含清单数 + bill_b1 = _q(server["db"], "SELECT id FROM bills WHERE batch_id=?", (b1,))[0][0] + bb = post(server, "/api/admin/batch/%d/inq/bind" % b1, {"file_id": fid, "bill_ids": [bill_b1]}) + assert bb["ok"] is True and bb["n"] == 1 + bl = get(server, "/api/admin/batch/%d/inq/bills" % b1) + assert bl["ok"] is True and bl["rows"] and bl["rows"][0]["file_id"] == fid + lst2 = get(server, "/api/admin/batch/%d/inq" % b1) + assert lst2["files"][0]["n"] == 2 # 1 工料机 + 1 清单 + unb = post(server, "/api/admin/batch/%d/inq/unbind" % b1, {"bill_ids": [bill_b1]}) + assert unb["ok"] is True and unb["n"] == 1 stored = _q(server["db"], "SELECT stored_path FROM inquiry_files WHERE id=?", (fid,))[0][0] fp = server["root"] / "CostReview" / "data" / stored assert fp.exists() diff --git a/CostReview/app/tests/test_lme_price.py b/CostReview/app/tests/test_lme_price.py index 587856c..5980af4 100644 --- a/CostReview/app/tests/test_lme_price.py +++ b/CostReview/app/tests/test_lme_price.py @@ -33,7 +33,7 @@ def _mk_sess(): c.execute("""CREATE TABLE s_lme_proj(id INTEGER PRIMARY KEY, session_id INT, code TEXT, name TEXT, spec TEXT, unit TEXT, kind INT, qty REAL, ntp REAL, taxrate REAL, taxp REAL, - x_adopt_added INTEGER DEFAULT 0, x_merged_hide INTEGER DEFAULT 0)""") + x_adopt_added INTEGER DEFAULT 0, x_merged_hide INTEGER DEFAULT 0, x_remark TEXT)""") c.execute("""CREATE TABLE s_lme_uw(id INTEGER PRIMARY KEY, session_id INT, uw_id INT, code TEXT, name TEXT, spec TEXT, unit TEXT, kind INT, qty REAL, ntp REAL, taxrate REAL, taxp REAL, x_adopt_added INTEGER DEFAULT 0)""") @@ -175,15 +175,16 @@ def test_no_price_fields_is_noop(): # ---------- 行形状(前后端同改的铁律处)---------- -def test_raw_proj_rows_are_nine_wide_with_taxrate_at_7(): - """项目级卡:行 9 列、税率在下标 7;ids 与行一一并行;隐藏行不给 id;含税价挪到下标 8。""" +def test_raw_proj_rows_are_eleven_wide_id_first(): + """决策 147(2026-10-21):项目级卡与「项目工料机」同形 —— 行 11 列 id 在首位、备注位 10; + 税率在下标 7、含税在下标 8;不再 rows/ids 分离;隐藏行被过滤。""" sc = _mk_sess() d = srv._raw_proj(sc, srv.TBL["session"], SID, "lme") assert len(d["rows"]) == 2 # 隐藏行被过滤 - assert all(len(r) == 9 for r in d["rows"]) + assert all(len(r) == 11 for r in d["rows"]) r0 = d["rows"][0] - assert r0[0] == "C1" and r0[6] == 99.99 and r0[7] == 3.5 and r0[8] == 103.49 - assert d["ids"] == [1, 2] # 与行一一并行,隐藏行(id=3)不在 + assert r0[0] == 1 and r0[1] == "C1" and r0[6] == 99.99 and r0[7] == 3.5 and r0[8] == 103.49 + assert "ids" not in d assert d["sub"] == ["P1"] @@ -210,8 +211,8 @@ def _mk_lmes(sc, with_taxrate=True): Quantity REAL, NoTaxPrice REAL, TaxPrice REAL%(tx)s)""" % {"tx": tx}) -def test_raw_proj_fallback_nine_wide_taxrate_at_7(): - """老会话(s_lme_proj 无数据)回退 lmes:仍 9 列、税率在下标 7、含税在下标 8;无 ids=只读。""" +def test_raw_proj_fallback_eleven_wide_taxrate_at_7(): + """老会话(s_lme_proj 无数据)回退 lmes:决策 147 后 11 列 id 首位、税率在下标 7、含税在下标 8;无 ids=只读。""" sc = _mk_sess() sc.execute("DELETE FROM s_lme_proj") _mk_lmes(sc, with_taxrate=True) @@ -220,8 +221,8 @@ def test_raw_proj_fallback_nine_wide_taxrate_at_7(): [("C1", "钢筋", "", 99.99, 3.5, 103.49), ("C2", "水泥", "", 200.0, 3.5, 207.0)]) d = srv._raw_proj(sc, srv.TBL["session"], SID, "lme") - assert all(len(r) == 9 for r in d["rows"]) - assert d["rows"][0][0] == "C1" and d["rows"][0][6] == 99.99 + assert all(len(r) == 11 for r in d["rows"]) + assert d["rows"][0][1] == "C1" and d["rows"][0][6] == 99.99 assert d["rows"][0][7] == 3.5 and d["rows"][0][8] == 103.49 assert "ids" not in d @@ -235,7 +236,7 @@ def test_raw_proj_fallback_without_taxrate_column(): Quantity, NoTaxPrice, TaxPrice) VALUES(1,'C1','钢筋','kg',2, 10, 99.99, 103.49)""") d = srv._raw_proj(sc, srv.TBL["session"], SID, "lme") r0 = d["rows"][0] - assert len(r0) == 9 and r0[6] == 99.99 and r0[7] is None and r0[8] == 103.49 + assert len(r0) == 11 and r0[6] == 99.99 and r0[7] is None and r0[8] == 103.49 def test_raw_uw_agg_fallback_nine_wide_taxrate_at_7(): @@ -382,10 +383,10 @@ def test_http_lme_price_end_to_end(server): "district": "香洲区", "period_from": PERIOD_202607, "period_to": PERIOD_202607, "file_kind": 1, "path": p})["session_id"] d = get(server, "/api/session/raw/proj", session_id=sid, tab="lme") - assert d["ok"] is True and d["rows"] and all(len(r) == 9 for r in d["rows"]) - rid = d["ids"][0] - assert d["ids"] and len(d["ids"]) == len(d["rows"]) - code = d["rows"][0][0] + # 决策 147:11 列 id 首位,不再 rows/ids 分离 + assert d["ok"] is True and d["rows"] and all(len(r) == 11 for r in d["rows"]) + rid = d["rows"][0][0] + code = d["rows"][0][1] # 改除税 99.99 + 税率 3.5 → 含税 103.49(主人给的例,服务端复核) r = post(server, "/api/session/lme/price", {"session_id": sid, "id": rid, "ntp": 99.99, "taxrate": 3.5}) diff --git a/CostReview/app/ui/admin.html b/CostReview/app/ui/admin.html index db6a509..713ecc9 100644 --- a/CostReview/app/ui/admin.html +++ b/CostReview/app/ui/admin.html @@ -15,7 +15,7 @@ body{font-family:"Source Han Sans SC","Noto Sans SC","Source Han Sans CN","MiSan align-items:flex-end —— 右侧「设置 / 工作台」两个按钮底部与标签对齐、保持自身自然高度(≈29px), 比标签矮 3px,一眼能分清「标签」和「按钮」,不用再靠 margin-bottom 人为错开。 */ .tabs{display:flex;align-items:flex-end;gap:4px;border-bottom:2px solid var(--c1)} -.tab{height:32px;display:flex;align-items:center;padding:0 22px;cursor:pointer; +.tab{height:24px;display:flex;align-items:center;padding:0 22px;cursor:pointer; /* 2026-10-21 决策 151 主人定:与工作台数据页签同高(原 32px 口径取消) */ border:1px solid var(--line);border-bottom:none;background:#e7edf5; color:#34506f;font-weight:600;font-size:13px;border-radius:8px 8px 0 0;user-select:none} .tab:hover{background:#dbe5f2} @@ -26,6 +26,33 @@ body{font-family:"Source Han Sans SC","Noto Sans SC","Source Han Sans CN","MiSan .dtab:hover{background:#dbe5f2} .dtab.on{background:var(--c1);color:#fff;border-color:var(--c1)} .tab.on{background:var(--c1);color:#fff;border-color:var(--c1)} +/* 动态明细标签(2026-10-21 决策 150 主人定):点「明细」在此追加浏览器式标签,× 可关; + 固定三标签(入库项目/市场价/信息价 = 一个项目、一份市场价数据、一份信息价数据)不可关。 + 外观同 .tab,但**不能用 .tab 类**(同 .dtab 的理由:页面标签脚本按 .tab 统一接管点击)。 + 标签文字 = 类型前缀(项目·/市场价·/信息价·)+ 数据名 + 色点 —— 一眼认出点开的是哪份数据(主人补充定)。 + #xtabs 占据固定三标签与右侧按钮之间的全部宽度,标签多时横向滚动(细滚动条)。 */ +#xtabs{display:flex;align-items:flex-end;gap:4px;flex:1;min-width:0;overflow-x:auto;overflow-y:hidden; + padding:0 2px;scrollbar-width:thin} +#xtabs::-webkit-scrollbar{height:4px} +.xtab{flex:none;max-width:260px;height:32px;display:flex;align-items:center;gap:6px;padding:0 8px 0 16px; + cursor:pointer;border:1px solid var(--line);border-bottom:none;background:#e7edf5; + color:#34506f;font-weight:600;font-size:13px;border-radius:8px 8px 0 0;user-select:none} +.xtab:hover{background:#dbe5f2} +.xtab.on{background:var(--c1);color:#fff;border-color:var(--c1)} +.xtab .kd{flex:none;width:8px;height:8px;border-radius:2px;background:#94a3b8} +.xtab .kd.project{background:#2563eb}.xtab .kd.market{background:#1a7f37}.xtab .kd.info{background:#d97706} +.xtab .kd.inq{background:#0e9488} /* 决策 152:附件标签色点 */ +.xtab .xl{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap} +.xtab .xx{flex:none;color:#8899aa;font-size:15px;line-height:1;padding:1px 5px;border-radius:4px} +.xtab .xx:hover{background:rgba(0,0,0,.18);color:#fff} +.xtab.on .xx{color:rgba(255,255,255,.85)} +/* 明细标签页容器(决策 150):顶替原明细弹框——与列表 .panel 同级的页面区块, + 高度由 JS 按视口吃满(同 availHeight 口径,.wrap 底部内边距 24px),内部 .db 各自滚动 */ +#dpage{display:none;flex-direction:column;background:#fff;border:1px solid var(--line);border-top:none;min-height:420px} +/* 附件动态标签页(决策 152):容器同 #dpage 口径;内部 qwrap 吃满剩余高度(原弹框定高取消) */ +#qpage{display:none;flex-direction:column;background:#fff;border:1px solid var(--line);border-top:none;min-height:420px} +.qhead{display:flex;align-items:center;gap:10px;padding:9px 14px;border-bottom:1px solid var(--line); + background:#fafcff;flex:none} .panel{background:#fff;border:1px solid var(--line);border-top:none} /* 查询栏:**强制单行**(2026-10-07 主人定:保证一行,不要 2 行)—— 可收缩控件按比例让宽,窗口放不下时查询栏内部出细横向滚动条(仍是一行)。 */ @@ -64,11 +91,10 @@ body{font-family:"Source Han Sans SC","Noto Sans SC","Source Han Sans CN","MiSan /* ---- 询价附件弹窗(2026-10-06)---- 左 38% 上传区 / 右 62% 工料机:右边 7 列给窄了必然横滚,等于白做。 中间 1px 实线 + 12px 间距,不用虚线 —— 虚线在这里不承载任何信息。 */ -.qwrap{display:flex;gap:12px;height:min(560px,66vh);padding:12px} -.qleft{width:38%;min-width:296px;display:flex;flex-direction:column;gap:8px; - border-right:1px solid #d8e0ec;padding-right:12px} +.qwrap{display:flex;gap:12px;flex:1;min-height:0;padding:12px} +.qleft{width:40%;min-width:296px;display:flex;flex-direction:column;gap:8px; + border-right:none;padding-right:0} /* 决策 153:默认 40%,分隔条拖宽后记忆 */ .qright{flex:1;display:flex;flex-direction:column;gap:8px;min-width:0} -.qsec{border:1px solid #c9d4e2;background:#fafcff;border-radius:6px;padding:10px} .qlist{flex:1;overflow:auto;border:1px solid #c9d4e2;border-radius:6px;background:#fff} .qitem{padding:8px 10px;border-bottom:1px solid #eef2f7;cursor:pointer; display:flex;gap:8px;align-items:flex-start;font-size:12.5px} @@ -86,6 +112,24 @@ body{font-family:"Source Han Sans SC","Noto Sans SC","Source Han Sans CN","MiSan .qlme td{border-bottom:1px solid #f0f3f8;padding:5px 8px;vertical-align:top} /* 已绑:整行底色 + 名称后灰标。只靠复选框勾中态分不清「本次新勾」和「之前已绑」 */ .qlme tr.bound{background:#f4f8ff} +/* 决策 152:右侧工作区顶部「项目工料机 / 类似清单」页签(同操作/明细的浏览器式块状页签) */ +.qtab{padding:5px 14px;cursor:pointer;border:1px solid var(--line);border-bottom:none; + background:#e7edf5;border-radius:8px 8px 0 0;font-size:12.5px;color:#374151;white-space:nowrap; + user-select:none} +.qtab:hover{background:#dbe5f2} +.qtab.on{background:var(--c1);color:#fff;border-color:var(--c1)} +.qtabs{display:flex;gap:4px;align-items:flex-end;border-bottom:1px solid var(--line);padding-right:8px} +.qtree .rt{font-weight:600;padding:6px 10px;background:#f4f8ff;border-bottom:1px solid #d8e0ec; + display:flex;align-items:center;gap:6px} +/* 决策 153:左右分隔条拖宽(记忆)+ 工作台同款按钮 + 搜索关键词黄色高亮 */ +.qsplit{flex:none;width:6px;cursor:col-resize;border-radius:3px;background:#e3e9f2} +.qsplit:hover{background:#c9d8ec} +.btn.wb{display:inline-flex;align-items:center;justify-content:center;height:28px;padding:0 12px; + border:1px solid #b8c4d4;border-radius:6px;background:#fff;cursor:pointer;font:inherit; + font-size:12.5px;color:#26405e;line-height:1;white-space:nowrap;vertical-align:middle; + user-select:none;flex:none} +.btn.wb:hover{background:#eef3fa} +mark.qhl{background:#ffe58f;color:inherit;padding:0 1px;border-radius:2px} .sum{color:var(--muted);font-size:12px;margin-left:auto} .sum b{color:#c0392b} /* .tw 高度由 JS 动态设(与行数自适应同源,见 autoSize/availHeight)—— @@ -113,26 +157,26 @@ td.name{overflow:hidden;text-overflow:ellipsis;white-space:nowrap} .pager{display:flex;gap:8px;align-items:center;justify-content:flex-end;padding:8px 12px;font-size:13px;color:var(--muted)} a{color:var(--c2);text-decoration:none} a:hover{text-decoration:underline} -.dlg .tabs{border-bottom:2px solid var(--c1)} +/* 明细子标签条已随决策 150 移出弹框、进页面标签页 #dpage(其余弹框没有 .tabs) */ +#dtabs{border-bottom:2px solid var(--c1)} .mask{position:fixed;inset:0;background:rgba(0,0,0,.35);display:none;align-items:center;justify-content:center;z-index:50} .mask.on{display:flex} -/* 明细弹框:主人 2026-10-01 要「同软件宽度」→ 跟随窗口,只在超宽屏上封顶 */ +/* 明细弹框宽度口径(主人 2026-10-01「同软件宽度」)现为其余弹框(导入/附件/编辑/字典/询价)通用 */ .dlg{background:#fff;border-radius:8px;width:96vw;max-width:1760px;max-height:92vh;display:flex;flex-direction:column} -/* 2026-10-08 主人定:明细弹框高度钉死 92vh —— 各标签内容高矮差异太大,内容撑高 + - 遮罩垂直居中 = 每次加载/切标签顶边都在跳。盒子尺寸恒定后,打开第一帧就落在最终 - 位置,数据加载、切标签、树展开全部零移动(内部 .db 本来就各自滚动)。 */ -#mask .dlg{height:92vh} +/* 2026-10-08「明细弹框高度钉死 92vh」已随决策 150(2026-10-21 主人定)作废:明细不再开弹框, + 改为页面内动态标签页 #dpage——高度吃满 .wrap 剩余空间、内部 .db 各自滚动, + 「盒子尺寸恒定、零移动」的思路原样保留,只是容器从遮罩弹框换成页面标签页。 */ .dlg .dh{display:flex;justify-content:space-between;align-items:center;padding:11px 16px; border-bottom:1px solid var(--line);background:var(--head);border-radius:8px 8px 0 0} .dlg .dh b{color:var(--c1);font-size:14px} -.dlg .db{overflow:auto;padding:0} +#dpage .db{overflow:auto;padding:0} /* 类似清单左组树(2026-10-08 主人定:后台同工作台):仅 p2 标签显示,dbody 转 flex 行、树占左列 */ #dbody.simflex{display:flex} #simtree{width:230px;flex:none;border-right:1px solid var(--line);overflow:auto;padding:6px 4px;background:#fcfdfe} .close{cursor:pointer;color:#8899aa;font-size:20px;line-height:1} .tip{color:var(--muted);font-size:12px;padding:6px 0} /* 明细:左侧目录 + 右侧内容(照上传 HTML 的版式) */ -.dlg .db.fx{display:flex;overflow:hidden} +#dpage .db.fx{display:flex;overflow:hidden} /* 原数据标签要跟工作台一样「左树 + 右卡 + 下方工料机面板」各自滚动: 必须给 #dright / #drawbox 撑出确定高度,否则 .rawbox 的 height:100% 在弹框里算不出来、整块塌陷。 */ #dright{flex:1;min-width:0;display:flex;flex-direction:column;min-height:0} @@ -236,12 +280,15 @@ td.pcell input{width:100%;padding:3px 7px;font-size:12.5px;border:1px solid #9fb