| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947 |
- <%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" session="true" %>
- <%@ page import="java.io.File" %>
- <%@ page import="java.nio.file.Files" %>
- <%@ page import="java.sql.Connection" %>
- <%@ page import="java.sql.PreparedStatement" %>
- <%@ page import="java.sql.ResultSet" %>
- <%@ page import="java.sql.ResultSetMetaData" %>
- <%@ page import="java.sql.Types" %>
- <%@ page import="java.text.SimpleDateFormat" %>
- <%@ page import="java.util.ArrayList" %>
- <%@ page import="java.util.Date" %>
- <%@ page import="java.util.LinkedHashMap" %>
- <%@ page import="java.util.LinkedHashSet" %>
- <%@ page import="java.util.List" %>
- <%@ page import="java.util.Map" %>
- <%@ page import="java.util.Set" %>
- <%@ page import="javax.naming.Context" %>
- <%@ page import="javax.naming.InitialContext" %>
- <%@ page import="javax.sql.DataSource" %>
- <%@ page import="ss.AppB" %>
- <%!
- /*
- * 学生/家长账号状态排查页(只读)
- *
- * 用途:输入 学生姓名 / 班级 / 学号 / 手机号,一次查出该学生及其家长的
- * 档案、校卡、权益、家长账号、订阅、手机号重复等状态,并给出结论标签。
- *
- * 约束:
- * 1. 只读:全部 SQL 均为 SELECT,无任何写操作。
- * 2. 页面口令不写在本文件里,从服务器上的口令文件读取(见 PWD_FILE_CANDIDATES);
- * 文件缺失时页面拒绝运行。
- * 3. 独立文件:不修改 web.xml、不修改 cfg/**、不新增/不依赖任何 Java 类。
- * 取数只用标准 JNDI + JDBC(java:comp/env/jdbc/dc),
- * 不调用 PMS 平台内部 API,避免受内部方法改名影响。
- */
- /** 一次最多展示多少名学生,避免按班级搜索时全量渲染。 */
- private static final int MAX_STUDENT = 60;
- /** 会话中“已通过口令校验”的标记。 */
- private static final String SESS_OK = "dcTsOk";
- /** 页面口令文件的候选位置(按顺序探测,取第一个存在的)。 */
- private static final String[] PWD_FILE_CANDIDATES = {
- "/usr/local/tomcat/conf/dc-troubleshoot.pwd",
- "/usr/local/tomcat/webapps/ROOT/WEB-INF/dc-troubleshoot.pwd",
- "/opt/data/tmp/dc-troubleshoot.pwd"
- };
- /** JNDI 数据源名(见 web/META-INF/context.xml)。 */
- private static final String JNDI_dc = "java:comp/env/jdbc/dc";
- /** 学生人员类别、在用记录状态。 */
- private static final long RYLBM_student = 1100;
- private static final long JLZTM_use = 51;
- /** 订阅包含的服务项目。 */
- private static final int GRFW_ITEM_COUNT = 6;
- private static String grfwName(long xmm) {
- switch ((int) xmm) {
- case 111: return "电话 ZDSC";
- case 115: return "留言 ZDLL";
- case 121: return "语音 ZDCS";
- case 122: return "视频";
- case 123: return "课程";
- case 124: return "其他";
- default: return String.valueOf(xmm);
- }
- }
- private static String txt(Object o) {
- return o == null ? "" : String.valueOf(o);
- }
- /** HTML 转义。 */
- private static String esc(Object o) {
- String s = txt(o);
- StringBuilder b = new StringBuilder(s.length() + 16);
- for (int i = 0; i < s.length(); i++) {
- char ch = s.charAt(i);
- switch (ch) {
- case '&': b.append("&"); break;
- case '<': b.append("<"); break;
- case '>': b.append(">"); break;
- case '"': b.append("""); break;
- case '\'': b.append("'"); break;
- default: b.append(ch);
- }
- }
- return b.toString();
- }
- private static String trimToNull(String s) {
- if (s == null) return null;
- s = s.trim();
- return s.isEmpty() ? null : s;
- }
- private static String dt(Object o) {
- if (o == null) return "";
- if (o instanceof Date) return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format((Date) o);
- return String.valueOf(o);
- }
- private static String d8(Object o) {
- if (o == null) return "";
- if (o instanceof Date) return new SimpleDateFormat("yyyy-MM-dd").format((Date) o);
- return String.valueOf(o);
- }
- /** 直接取 Map 里的值格式化(cell() 会把值转成 String,不能再交给 dt())。 */
- private static String dtm(Map<String, Object> m, String key) {
- return dt(m.get(key));
- }
- private static String d8m(Map<String, Object> m, String key) {
- return d8(m.get(key));
- }
- /** 布尔(含 Y/N、1/0) 转 是/否。 */
- private static String yn(Object o) {
- String s = txt(o);
- if (s.isEmpty()) return "";
- if ("Y".equalsIgnoreCase(s) || "1".equals(s) || "TRUE".equalsIgnoreCase(s)) return "是";
- if ("N".equalsIgnoreCase(s) || "0".equals(s) || "FALSE".equalsIgnoreCase(s)) return "否";
- return s;
- }
- private static String num(Object o) {
- if (o == null) return "0";
- if (o instanceof Number) {
- Number n = (Number) o;
- if (n.doubleValue() == Math.floor(n.doubleValue())) return String.valueOf(n.longValue());
- }
- return String.valueOf(o);
- }
- private static long lng(Object o) {
- if (o == null) return 0L;
- if (o instanceof Number) return ((Number) o).longValue();
- try {
- return Long.parseLong(String.valueOf(o).trim());
- } catch (Exception e) {
- return 0L;
- }
- }
- /** 是否像手机号(11 位、以 1 开头、全数字)。学生的“账号”是姓名,不能当手机号统计。 */
- private static boolean isPhone(String s) {
- if (s == null) return false;
- String t = s.trim();
- if (t.length() != 11 || t.charAt(0) != '1') return false;
- for (int i = 1; i < t.length(); i++) {
- if (!Character.isDigit(t.charAt(i))) return false;
- }
- return true;
- }
- /** 读取页面口令;口令不写在代码里。 */
- private static String rdPagePwd() {
- for (String p : PWD_FILE_CANDIDATES) {
- try {
- File f = new File(p);
- if (f.isFile()) {
- String s = new String(Files.readAllBytes(f.toPath()),
- java.nio.charset.StandardCharsets.UTF_8).trim();
- if (!s.isEmpty()) return s;
- }
- } catch (Exception ignore) {
- // 忽略,继续探测下一个候选路径。
- }
- }
- return null;
- }
- /** 判断 sauth 目录下是否存在 rygw<人员ID> 序列化文件(家长权限缓存)。 */
- private static boolean sauthCacheExists(long ryid) {
- String dir = AppB.cfgSauthDir;
- if (dir == null) return false;
- String fileName = "rygw" + ryid;
- try {
- File d = new File(dir);
- if (new File(d, fileName).exists()) return true;
- File[] subs = d.listFiles();
- if (subs != null) {
- for (File s : subs) {
- if (s.isDirectory() && new File(s, fileName).exists()) return true;
- }
- }
- } catch (Exception ignore) {
- // 忽略。
- }
- return false;
- }
- private static String tag(String cls, String text) {
- return "<span class=\"tag " + cls + "\">" + esc(text) + "</span> ";
- }
- private static Connection getConn() throws Exception {
- Context ctx = new InitialContext();
- DataSource ds = (DataSource) ctx.lookup(JNDI_dc);
- Connection conn = ds.getConnection();
- try { conn.setAutoCommit(true); } catch (Exception ignore) { }
- return conn;
- }
- /**
- * 时间列统一取成 java.sql.Timestamp。
- * 实测 getObject( 对 DATE/TIMESTAMP 列可能返回非 java.util.Date 的实现类,
- * 直接用 instanceof 判断会漏掉,导致格式化不生效。
- */
- private static Object readTime(ResultSet rs, int idx) {
- try {
- java.sql.Timestamp ts = rs.getTimestamp(idx);
- if (ts != null) return ts;
- } catch (Exception ignore) {
- // 落到 getObject。
- }
- try {
- return rs.getObject(idx);
- } catch (Exception ignore) {
- return null;
- }
- }
- /** 只读查询:SQL 用 ? 占位,params 按顺序传入。结果列名统一转小写。 */
- private static List<Map<String, Object>> query(Connection conn, String sql, Object... params) throws Exception {
- List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
- PreparedStatement ps = null;
- ResultSet rs = null;
- try {
- ps = conn.prepareStatement(sql);
- int n = params == null ? 0 : params.length;
- for (int i = 0; i < n; i++) {
- Object p = params[i];
- if (p == null) ps.setNull(i + 1, Types.VARCHAR);
- else if (p instanceof Long) ps.setLong(i + 1, ((Long) p).longValue());
- else if (p instanceof Integer) ps.setInt(i + 1, ((Integer) p).intValue());
- else ps.setString(i + 1, String.valueOf(p));
- }
- rs = ps.executeQuery();
- ResultSetMetaData md = rs.getMetaData();
- int colCount = md.getColumnCount();
- String[] names = new String[colCount];
- boolean[] isTime = new boolean[colCount];
- for (int i = 1; i <= colCount; i++) {
- names[i - 1] = md.getColumnLabel(i).toLowerCase();
- int t = md.getColumnType(i);
- isTime[i - 1] = (t == Types.TIMESTAMP || t == Types.TIMESTAMP_WITH_TIMEZONE
- || t == Types.DATE || t == Types.TIME);
- }
- while (rs.next()) {
- Map<String, Object> row = new LinkedHashMap<String, Object>();
- for (int i = 1; i <= colCount; i++) {
- row.put(names[i - 1], isTime[i - 1] ? readTime(rs, i) : rs.getObject(i));
- }
- list.add(row);
- }
- } finally {
- if (rs != null) { try { rs.close(); } catch (Exception ignore) { } }
- if (ps != null) { try { ps.close(); } catch (Exception ignore) { } }
- }
- return list;
- }
- private static String cell(Map<String, Object> m, String key) {
- return txt(m.get(key));
- }
- %>
- <%
- request.setCharacterEncoding("UTF-8");
- // ============================ 1. 口令门 ============================
- String pwdErr = null;
- if ("logout".equals(request.getParameter("do"))) {
- session.removeAttribute(SESS_OK);
- }
- String realPwd = rdPagePwd();
- boolean authed = Boolean.TRUE.equals(session.getAttribute(SESS_OK));
- if (!authed) {
- String input = request.getParameter("pwd");
- if (realPwd == null) {
- pwdErr = "页面口令文件不存在,请管理员在服务器上创建:" + PWD_FILE_CANDIDATES[0];
- } else if (input != null) {
- if (realPwd.equals(input)) {
- session.setAttribute(SESS_OK, Boolean.TRUE);
- authed = true;
- } else {
- pwdErr = "口令不正确";
- }
- }
- }
- %>
- <!DOCTYPE html>
- <html lang="zh-CN">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <title>学生/家长账号状态排查</title>
- <style>
- body { font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif; margin: 0; padding: 16px 20px 60px; background: #f5f6f8; color: #222; font-size: 13px; }
- h1 { font-size: 18px; margin: 0 0 4px; }
- h2 { font-size: 15px; margin: 0 0 10px; }
- .sub { color: #666; margin-bottom: 14px; }
- .card { background: #fff; border: 1px solid #e2e5ea; border-radius: 6px; padding: 12px 14px; margin-bottom: 12px; }
- .stu { border-left: 4px solid #2b6cb0; }
- .block { margin-top: 12px; }
- .block > h3 { font-size: 13px; margin: 0 0 6px; color: #2b6cb0; border-bottom: 1px solid #eef1f5; padding-bottom: 4px; }
- table { border-collapse: collapse; width: 100%; }
- th, td { border: 1px solid #e6e9ee; padding: 4px 6px; text-align: left; vertical-align: top; word-break: break-all; }
- th { background: #fafbfc; font-weight: 600; white-space: nowrap; }
- .kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 2px 14px; }
- .kv div { padding: 1px 0; }
- .kv b { color: #555; font-weight: 500; }
- .tag { display: inline-block; padding: 1px 6px; border-radius: 10px; font-size: 12px; margin: 0 3px 3px 0; }
- .tag-danger { background: #fdecea; color: #b3261e; border: 1px solid #f5c6c2; }
- .tag-warn { background: #fff4e5; color: #a35a00; border: 1px solid #ffd8a8; }
- .tag-ok { background: #e7f6ec; color: #1b7a3d; border: 1px solid #b7e0c4; }
- .tag-info { background: #eef1f5; color: #55606e; border: 1px solid #dde2e8; }
- form.f { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: flex-end; }
- form.f label { display: flex; flex-direction: column; gap: 3px; color: #555; }
- input[type=text], input[type=password], select { padding: 5px 7px; border: 1px solid #ccd2da; border-radius: 4px; font-size: 13px; min-width: 150px; }
- button { padding: 6px 16px; border: 0; border-radius: 4px; background: #2b6cb0; color: #fff; font-size: 13px; cursor: pointer; }
- .login { max-width: 380px; margin: 80px auto; background: #fff; border: 1px solid #e2e5ea; border-radius: 8px; padding: 26px 28px; }
- .login form { display: flex; gap: 8px; margin-top: 14px; }
- .login input { flex: 1; }
- .err { color: #b3261e; margin-top: 10px; }
- .hint { color: #777; }
- .mono { font-family: ui-monospace, Menlo, Consolas, monospace; }
- .stuhead { display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: baseline; }
- .stuhead .name { font-size: 16px; font-weight: 600; }
- .bad { color: #b3261e; font-weight: 600; }
- </style>
- </head>
- <body>
- <%
- if (!authed) {
- %>
- <div class="login">
- <h2>学生/家长账号状态排查</h2>
- <div class="hint">请输入页面口令后进入。本页仅内部排查使用,只读、无修复功能。</div>
- <form method="post" action="DcTroubleshoot.jsp">
- <input type="password" name="pwd" placeholder="页面口令" autofocus autocomplete="off">
- <button type="submit">进入</button>
- </form>
- <% if (pwdErr != null) { %><div class="err"><%= esc(pwdErr) %></div><% } %>
- </div>
- </body>
- </html>
- <%
- return;
- }
- // ============================ 2. 搜索条件与数据取数 ============================
- String pXm = trimToNull(request.getParameter("xm"));
- String pRyh = trimToNull(request.getParameter("ryh"));
- String pSjh = trimToNull(request.getParameter("sjh"));
- String pBjid = trimToNull(request.getParameter("bjid"));
- Long pBjidVal = null;
- if (pBjid != null) {
- try { pBjidVal = Long.valueOf(pBjid); } catch (Exception ignore) { }
- }
- boolean pAll = "1".equals(request.getParameter("all"));
- boolean searched = request.getParameter("xm") != null || request.getParameter("ryh") != null
- || request.getParameter("sjh") != null || request.getParameter("bjid") != null
- || request.getParameter("all") != null;
- boolean hasCond = pXm != null || pRyh != null || pSjh != null || pBjidVal != null;
- Connection conn = null;
- List<Map<String, Object>> classList = new ArrayList<Map<String, Object>>();
- List<Map<String, Object>> stuList = new ArrayList<Map<String, Object>>();
- String queryErr = null;
- StringBuilder diag = new StringBuilder();
- try {
- conn = getConn();
- // 班级下拉:BJ 中在用班级。
- classList = query(conn,
- "select b.bjid, b.mc, b.njm, b.dwid, d.mc dwmc"
- + " from bj b left join dw d on d.dwid = b.dwid"
- + " where b.jlztm = " + JLZTM_use
- + " order by b.njm, b.mc");
- if (searched && hasCond) {
- StringBuilder sql = new StringBuilder();
- List<Object> args = new ArrayList<Object>();
- sql.append("select * from (select r.ryid, r.xm, r.ryh, r.zh, r.grdh, r.rylbm, r.jlztm, r.ryztm, ")
- .append(" case when r.sfqy then 'Y' else 'N' end sfqy_y, r.dlcwcs, ")
- .append(" r.dwid, dw.mc dwmc, r.gwid, gw.mc gwmc, r.kaid, r.fzjzid, r.scdlsj, ")
- .append(" r.import_mark, r.pic_import_mark, r.src_excel, ")
- .append(" b.bjid, b.mc bjmc, b.njm, ")
- .append(" (select count(*) from ryka k where k.ryid = r.ryid) ryka_cnt, ")
- .append(" (select count(*) from jtcy j where j.ryid = r.ryid) jz_cnt ")
- .append(" from ry r ")
- .append(" left join bjcy bc on bc.ryid = r.ryid ")
- .append(" left join bj b on b.bjid = bc.bjid ")
- .append(" left join dw dw on dw.dwid = r.dwid ")
- .append(" left join gw gw on gw.gwid = r.gwid ")
- .append(" where r.rylbm = ").append(RYLBM_student).append(" ");
- if (!pAll) sql.append(" and r.jlztm = ").append(JLZTM_use).append(" ");
- if (pXm != null) { sql.append(" and r.xm like ? "); args.add("%" + pXm + "%"); }
- if (pRyh != null) { sql.append(" and r.ryh = ? "); args.add(pRyh); }
- if (pBjidVal != null) { sql.append(" and b.bjid = ? "); args.add(pBjidVal); }
- if (pSjh != null) {
- // 手机号反查:学生本人电话/账号/人员号,或家长关系里的手机,或家长账号的手机。
- sql.append(" and ( r.ryid in (select ryid from ry where jlztm = ").append(JLZTM_use)
- .append(" and (grdh = ? or zh = ? or ryh = ?)) ")
- .append(" or r.ryid in (select c.ryid from jtcy c where c.grdh = ?) ")
- .append(" or r.ryid in (select c.ryid from jtcy c join ry p on p.ryid = c.jzid")
- .append(" where p.grdh = ? or p.zh = ? or p.ryh = ?) ) ");
- for (int i = 0; i < 7; i++) args.add(pSjh);
- }
- sql.append(" order by b.njm, b.mc, r.ryh ) where rownum <= ").append(MAX_STUDENT);
- stuList = query(conn, sql.toString(), args.toArray());
- }
- } catch (Exception e) {
- queryErr = e.getClass().getSimpleName() + ": " + e.getMessage();
- }
- %>
- <h1>学生/家长账号状态排查</h1>
- <div class="sub">
- 按 姓名 / 班级 / 学号 / 手机号 查询学生档案、校卡绑定、权益、家长账号、订阅同步状态。
- 本页只读,不含任何修复操作。
- <a href="DcTroubleshoot.jsp?do=logout">退出</a>
- </div>
- <div class="card">
- <form class="f" method="get" action="DcTroubleshoot.jsp">
- <label>学生姓名<input type="text" name="xm" value="<%= esc(pXm) %>" placeholder="支持模糊,如 林盈盈"></label>
- <label>班级
- <select name="bjid">
- <option value="">(不限)</option>
- <%
- for (Map<String, Object> c : classList) {
- String bjid = cell(c, "bjid");
- boolean sel = bjid.equals(pBjid);
- %>
- <option value="<%= esc(bjid) %>"<%= sel ? " selected" : "" %>><%= esc(cell(c, "mc")) %> · <%= esc(cell(c, "dwmc")) %></option>
- <%
- }
- %>
- </select>
- </label>
- <label>学号<input type="text" name="ryh" value="<%= esc(pRyh) %>" placeholder="精确,如 220118175"></label>
- <label>手机号反查<input type="text" name="sjh" value="<%= esc(pSjh) %>" placeholder="家长或学生手机号"></label>
- <label>范围
- <select name="all">
- <option value="">仅在看(在用学员)</option>
- <option value="1"<%= pAll ? " selected" : "" %>>含历史/已注销人员</option>
- </select>
- </label>
- <button type="submit">搜索</button>
- </form>
- </div>
- <%
- if (queryErr != null) {
- %>
- <div class="card"><span class="tag tag-danger">查询失败</span> <span class="mono"><%= esc(queryErr) %></span></div>
- <%
- } else if (searched && hasCond) {
- %>
- <div class="card">
- 命中 <b><%= stuList.size() %></b> 名学生<%= stuList.size() >= MAX_STUDENT ? "(已达上限 " + MAX_STUDENT + ",请缩小条件)" : "" %>。
- </div>
- <%
- if (stuList.isEmpty()) {
- %>
- <div class="card"><span class="tag tag-info">无结果</span>
- 未找到匹配学员。可尝试:确认姓名写法、加上班级、或用学号/手机号精确反查;
- 若为已毕业人员,请把“范围”改为“含历史/已注销人员”。
- </div>
- <%
- }
- } else if (searched) {
- %>
- <div class="card"><span class="tag tag-info">请至少填写一个条件</span> 姓名、班级、学号、手机号任填其一。</div>
- <%
- }
- %>
- <%
- // ============================ 3. 逐个学生的明细 ============================
- if (queryErr == null && !stuList.isEmpty()) {
- try {
- for (Map<String, Object> s : stuList) {
- try {
- long ryid = lng(cell(s, "ryid"));
- String ryh = cell(s, "ryh");
- List<Map<String, Object>> parents = query(conn,
- "select c.jtcyid, c.jzid, c.xm jtcy_xm, c.grdh jtcy_grdh, c.jtgxm, c.jlztm jtcy_jlztm,"
- + " case when c.is_fzjz then 'Y' else 'N' end c_isfzjz,"
- + " p.zh p_zh, p.ryh p_ryh, p.grdh p_grdh, p.xm p_xm, p.rylbm p_rylbm, p.jlztm p_jlztm,"
- + " case when p.sfqy then 'Y' else 'N' end p_sfqy, p.dlcwcs p_dlcwcs, p.wbid2 p_wbid2,"
- + " p.scdlsj p_scdlsj, p.gwid p_gwid, gw.mc p_gwmc, p.dwid p_dwid,"
- + " l.mm l_mm, case when l.sfcsmm then 'Y' else 'N' end l_sfcsmm, l.gxsj l_gxsj"
- + " from jtcy c"
- + " left join ry p on p.ryid = c.jzid"
- + " left join gw gw on gw.gwid = p.gwid"
- + " left join lsmm l on l.ryid = c.jzid and l.jlztm = " + JLZTM_use
- + " where c.ryid = ?"
- + " order by c.jzid",
- ryid);
- List<Map<String, Object>> grfw = query(conn,
- "select grfwxmm, zdsc, zdll, zdcs, ljsc, ljll, ljcs, jzsj, jlztm,"
- + " case when sfty then 'Y' else 'N' end sfty_y"
- + " from grfw where ryid = ? order by grfwxmm",
- ryid);
- List<Map<String, Object>> ryka = query(conn,
- "select k.rykaid, k.kaid, k.jlztm ryka_jlztm,"
- + " ka.kah, ka.kaztm, ka.jlztm ka_jlztm, ka.mc ka_mc, ka.yxq"
- + " from ryka k left join ka on ka.kaid = k.kaid"
- + " where k.ryid = ? order by k.rykaid",
- ryid);
- List<Map<String, Object>> kaidCard = new ArrayList<Map<String, Object>>();
- String kaid = cell(s, "kaid");
- if (!kaid.isEmpty()) {
- kaidCard = query(conn,
- "select kaid, kah, kaztm, jlztm, yxq, mc from ka where kaid = ?",
- lng(kaid));
- }
- List<Map<String, Object>> makeCards = new ArrayList<Map<String, Object>>();
- if (!ryh.isEmpty()) {
- makeCards = query(conn,
- "select j.ryjhsjid, j.ryh, j.kah, j.bdsj, j.nfch, j.jlztm,"
- + " (select count(*) from xfjsjjh x where x.ryjhsjid = j.ryjhsjid and x.jlztm = " + JLZTM_use + ") sx_all,"
- + " (select count(*) from xfjsjjh x where x.ryjhsjid = j.ryjhsjid and x.jlztm = " + JLZTM_use
- + " and case when x.sfygx then 1 else 0 end = 1) sx_ok,"
- + " (select count(*) from ka k2 where k2.kah = j.kah) kh_in_ka"
- + " from ryjhsj j where j.ryh = ? order by j.bdsj desc",
- ryh);
- }
- List<Map<String, Object>> subs = query(conn,
- "select application_no, student_name, guardian_name, guardian_mobile, grade_name, class_name,"
- + " application_status, sync_status, pms_ryid, pms_jzid, paid_at, pay_order_no,"
- + " selected_package_name, amount_paid_cent, channel_code, remark, created_at"
- + " from c##dc_py.pp_application"
- + " where pms_ryid = ?"
- + " or pms_jzid in (select jzid from jtcy where ryid = ? and jzid is not null)"
- + " or guardian_mobile in (select grdh from jtcy where ryid = ? and grdh is not null)"
- + " or guardian_mobile in (select p.grdh from jtcy c join ry p on p.ryid = c.jzid"
- + " where c.ryid = ? and p.grdh is not null)"
- + " order by paid_at desc nulls last",
- ryid, ryid, ryid, ryid);
- List<Map<String, Object>> syncTasks = query(conn,
- "select application_no, sync_status, note, pms_ryid, pms_jzid, last_sync_at, updated_at"
- + " from c##dc_py.pp_sync_task"
- + " where pms_ryid = ?"
- + " or pms_jzid in (select jzid from jtcy where ryid = ? and jzid is not null)"
- + " order by updated_at desc nulls last",
- ryid, ryid);
- // ---- 手机号重复检查 ----
- Set<String> phones = new LinkedHashSet<String>();
- if (isPhone(cell(s, "grdh"))) phones.add(cell(s, "grdh").trim());
- if (isPhone(cell(s, "zh"))) phones.add(cell(s, "zh").trim());
- for (Map<String, Object> p : parents) {
- String ph = cell(p, "jtcy_grdh");
- if (ph.isEmpty()) ph = cell(p, "p_grdh");
- if (isPhone(ph)) phones.add(ph.trim());
- }
- Map<String, Integer> phoneAccounts = new LinkedHashMap<String, Integer>();
- for (String ph : phones) {
- List<Map<String, Object>> cnt = query(conn,
- "select count(*) cnt from ("
- + " select ryid from ry where jlztm = " + JLZTM_use + " and (grdh = ? or zh = ? or ryh = ?)"
- + " union"
- + " select jzid from jtcy where grdh = ? and jzid is not null"
- + " )",
- ph, ph, ph, ph);
- phoneAccounts.put(ph, cnt.isEmpty() ? 0 : (int) lng(cnt.get(0).get("cnt")));
- }
- // ---- 诊断标签 ----
- List<String> tags = new ArrayList<String>();
- String gwid = cell(s, "gwid");
- boolean gwidEmpty = gwid.isEmpty() || "0".equals(gwid);
- if (gwidEmpty) tags.add(tag("tag-danger", "岗位GWID为空 → 登录/刷卡会报500"));
- if (cell(s, "dwid").isEmpty()) tags.add(tag("tag-warn", "DWID(单位)为空"));
- if (cell(s, "bjmc").isEmpty()) tags.add(tag("tag-warn", "未分班(无班级记录)"));
- if (!"Y".equalsIgnoreCase(cell(s, "sfqy_y"))) tags.add(tag("tag-warn", "账号未启用(SFQY=N)"));
- if (lng(cell(s, "dlcwcs")) > 0) tags.add(tag("tag-warn", "登录错误次数=" + num(cell(s, "dlcwcs"))));
- if (kaid.isEmpty() && ryka.isEmpty()) {
- tags.add(tag("tag-danger", "卡未绑定(RY.KAID空且RYKA无记录) → 刷卡提示“卡无登记”"));
- } else if (kaid.isEmpty() && !ryka.isEmpty()) {
- tags.add(tag("tag-warn", "RY.KAID为空但有RYKA绑定记录,档案主卡未设置"));
- }
- if (!makeCards.isEmpty() && kaid.isEmpty()) {
- tags.add(tag("tag-warn", "有制卡记录(" + makeCards.size() + "条)但未绑定到档案"));
- }
- if (!makeCards.isEmpty()) {
- long sxAll = lng(makeCards.get(0).get("sx_all"));
- long sxOk = lng(makeCards.get(0).get("sx_ok"));
- // 说明:实测多数卡的“已更新”数量为 23/39 等 <100%,属常态,不影响刷卡登录,
- // 因此只在“一台都没下发”时报黄,其余只作中性提示,避免误导排查。
- if (sxOk == 0) tags.add(tag("tag-warn", "最新卡未下发到任何消费机"));
- else if (sxOk < sxAll) tags.add(tag("tag-info", "最新卡已下发 " + sxOk + "/" + sxAll + " 台(常态,通常不影响刷卡)"));
- if (lng(makeCards.get(0).get("kh_in_ka")) == 0) tags.add(tag("tag-warn", "最新制卡卡号不在 KA 卡库中"));
- }
- int grfwFound = 0;
- boolean grfwAllExpired = !grfw.isEmpty();
- Date now = new Date();
- for (Map<String, Object> g : grfw) {
- grfwFound++;
- Object jzsj = g.get("jzsj");
- if (!(jzsj instanceof Date) || ((Date) jzsj).after(now)) grfwAllExpired = false;
- }
- if (grfw.isEmpty()) {
- tags.add(tag("tag-danger", "无任何权益记录(GRFW为空) → 电话/留言/语音均不可用"));
- } else {
- if (grfwFound < GRFW_ITEM_COUNT) tags.add(tag("tag-warn", "权益不完整:" + grfwFound + "/" + GRFW_ITEM_COUNT + " 项"));
- if (grfwAllExpired) tags.add(tag("tag-danger", "权益已全部到期"));
- }
- for (Map<String, Object> p : parents) {
- long jzid = lng(p.get("jzid"));
- if (jzid == 0) { tags.add(tag("tag-warn", "存在未绑定家长的 JTCY 记录")); continue; }
- if (!sauthCacheExists(jzid)) tags.add(tag("tag-warn", "家长" + jzid + "缺权限缓存(rygw) → 小程序看不到入口"));
- if ("Y".equalsIgnoreCase(cell(p, "l_sfcsmm"))) tags.add(tag("tag-warn", "家长" + jzid + "仍标记为初始密码 → 登录会被要求改密"));
- if (cell(p, "p_gwid").isEmpty()) tags.add(tag("tag-warn", "家长" + jzid + "岗位为空"));
- }
- if (parents.isEmpty()) tags.add(tag("tag-info", "无家长关系记录(JTCY为空)"));
- for (Map.Entry<String, Integer> e : phoneAccounts.entrySet()) {
- if (e.getValue() > 1) {
- tags.add(tag("tag-warn", "手机号 " + e.getKey() + " 命中 " + e.getValue() + " 个账号 → 一键登录会提示多个账号"));
- }
- }
- boolean anySub = false;
- for (Map<String, Object> a : subs) {
- anySub = true;
- String syncStatus = cell(a, "sync_status");
- if (!"SUCCESS".equalsIgnoreCase(syncStatus)) {
- tags.add(tag("tag-warn", "订阅未同步 " + cell(a, "application_no")
- + ":" + (syncStatus.isEmpty() ? "PENDING" : syncStatus)));
- }
- }
- if (!anySub) tags.add(tag("tag-info", "按 学生RYID/家长JZID/手机号 未匹配到订阅申请"));
- %>
- <div class="card stu">
- <div class="stuhead">
- <span class="name"><%= esc(cell(s, "xm")) %></span>
- <span>学号 <b class="mono"><%= esc(ryh) %></b></span>
- <span>班级 <b><%= esc(cell(s, "bjmc")) %></b></span>
- <span class="mono">RYID <%= esc(cell(s, "ryid")) %></span>
- <span>单位 <%= esc(cell(s, "dwmc")) %></span>
- </div>
- <div class="block">
- <h3>诊断结论</h3>
- <div><%= tags.isEmpty() ? tag("tag-ok", "未发现异常") : String.join("", tags) %></div>
- </div>
- <div class="block">
- <h3>1. 学生档案</h3>
- <div class="kv">
- <div><b>RYID:</b><span class="mono"><%= esc(cell(s, "ryid")) %></span></div>
- <div><b>姓名:</b><%= esc(cell(s, "xm")) %></div>
- <div><b>学号:</b><span class="mono"><%= esc(ryh) %></span></div>
- <div><b>班级:</b><%= esc(cell(s, "bjmc")) %>(NJM <%= esc(cell(s, "njm")) %>)</div>
- <div><b>账号ZH:</b><%= esc(cell(s, "zh")) %></div>
- <div><b>个人电话GRDH:</b><%= esc(cell(s, "grdh")) %></div>
- <div><b>人员类别RYLBM:</b><%= esc(cell(s, "rylbm")) %></div>
- <div><b>记录状态JLZTM:</b><%= esc(cell(s, "jlztm")) %><%= JLZTM_use == lng(cell(s, "jlztm")) ? "(在用)" : "" %></div>
- <div><b>人员状态RYZTM:</b><%= esc(cell(s, "ryztm")) %></div>
- <div><b>是否启用SFQY:</b><%= yn(cell(s, "sfqy_y")) %></div>
- <div><b>登录错误次数:</b><%= esc(cell(s, "dlcwcs")) %></div>
- <div><b>单位DWID:</b><%= esc(cell(s, "dwid")) %> <%= esc(cell(s, "dwmc")) %></div>
- <div><b>岗位GWID:</b><%= esc(gwid) %> <%= esc(cell(s, "gwmc")) %><%= gwidEmpty ? tag("tag-danger", "为空") : "" %></div>
- <div><b>部门BMID:</b><%= esc(cell(s, "bmid")) %></div>
- <div><b>负责家长FZJZID:</b><span class="mono"><%= esc(cell(s, "fzjzid")) %></span></div>
- <div><b>上次登录SCDLSJ:</b><%= dtm(s, "scdlsj") %></div>
- <div><b>导入标记IMPORT_MARK:</b><%= esc(cell(s, "import_mark")) %></div>
- <div><b>照片导入标记:</b><%= esc(cell(s, "pic_import_mark")) %></div>
- <div><b>来源表SRC_EXCEL:</b><%= esc(cell(s, "src_excel")) %></div>
- </div>
- </div>
- <div class="block">
- <h3>2. 校卡绑定</h3>
- <table>
- <tr><th>来源</th><th>KAID</th><th>卡号KAH</th><th>卡状态KAZTM</th><th>有效期YXQ</th><th>在用状态</th><th>备注</th></tr>
- <tr>
- <td>RY.KAID(档案主卡)</td>
- <td><%= esc(kaid) %></td>
- <td><%= kaidCard.isEmpty() ? "" : esc(cell(kaidCard.get(0), "kah")) %></td>
- <td><%= kaidCard.isEmpty() ? "" : esc(cell(kaidCard.get(0), "kaztm")) %></td>
- <td><%= kaidCard.isEmpty() ? "" : dtm(kaidCard.get(0), "yxq") %></td>
- <td><%= kaidCard.isEmpty() ? "" : esc(cell(kaidCard.get(0), "jlztm")) %></td>
- <td><%= kaid.isEmpty() ? "<span class=\"bad\">未设置</span>" : "" %></td>
- </tr>
- <%
- for (Map<String, Object> k : ryka) {
- %>
- <tr>
- <td>RYKA 绑定</td>
- <td><%= esc(cell(k, "kaid")) %></td>
- <td><%= esc(cell(k, "kah")) %></td>
- <td><%= esc(cell(k, "kaztm")) %></td>
- <td><%= dtm(k, "yxq") %></td>
- <td>RYKA <%= esc(cell(k, "ryka_jlztm")) %> / 卡 <%= esc(cell(k, "ka_jlztm")) %></td>
- <td>RYKAID <%= esc(cell(k, "rykaid")) %></td>
- </tr>
- <%
- }
- if (ryka.isEmpty()) {
- %>
- <tr><td>RYKA 绑定</td><td colspan="6"><span class="bad">无绑定记录</span></td></tr>
- <%
- }
- %>
- </table>
- <div class="hint" style="margin-top:6px">
- 制卡记录(来自打印机项目,按学号):共 <%= makeCards.size() %> 条;“下发”= 该卡号推送到多少台消费机。
- </div>
- <table style="margin-top:6px">
- <tr><th>制卡ID</th><th>学号</th><th>卡号</th><th>制卡时间</th><th>房号NFCH</th><th>在KA卡库</th><th>下发(已更新/总数)</th></tr>
- <%
- for (Map<String, Object> m : makeCards) {
- %>
- <tr>
- <td class="mono"><%= esc(cell(m, "ryjhsjid")) %></td>
- <td class="mono"><%= esc(cell(m, "ryh")) %></td>
- <td class="mono"><%= esc(cell(m, "kah")) %></td>
- <td><%= dtm(m, "bdsj") %></td>
- <td><%= esc(cell(m, "nfch")) %></td>
- <td><%= lng(cell(m, "kh_in_ka")) > 0 ? "是" : "<span class=\"bad\">否</span>" %></td>
- <td><%= num(cell(m, "sx_ok")) %> / <%= num(cell(m, "sx_all")) %></td>
- </tr>
- <%
- }
- if (makeCards.isEmpty()) {
- %>
- <tr><td colspan="7">无制卡记录</td></tr>
- <%
- }
- %>
- </table>
- </div>
- <div class="block">
- <h3>3. 服务权益(GRFW)</h3>
- <table>
- <tr><th>项目</th><th>ZDSC</th><th>LJSC</th><th>ZDLL</th><th>LJLL</th><th>ZDCS</th><th>LJCS</th><th>JZSJ 截止</th><th>停用SFTY</th><th>在用状态</th></tr>
- <%
- for (Map<String, Object> g : grfw) {
- Object jzsj = g.get("jzsj");
- boolean expired = (jzsj instanceof Date) && !((Date) jzsj).after(new Date());
- %>
- <tr>
- <td><%= esc(grfwName(lng(g.get("grfwxmm")))) %></td>
- <td><%= num(g.get("zdsc")) %></td>
- <td><%= num(g.get("ljsc")) %></td>
- <td><%= num(g.get("zdll")) %></td>
- <td><%= num(g.get("ljll")) %></td>
- <td><%= num(g.get("zdcs")) %></td>
- <td><%= num(g.get("ljcs")) %></td>
- <td><%= dt(jzsj) %><%= expired ? " " + tag("tag-danger", "已过期") : "" %></td>
- <td><%= yn(cell(g, "sfty_y")) %></td>
- <td><%= esc(cell(g, "jlztm")) %></td>
- </tr>
- <%
- }
- if (grfw.isEmpty()) {
- %>
- <tr><td colspan="10"><span class="bad">无任何权益记录</span></td></tr>
- <%
- }
- %>
- </table>
- </div>
- <div class="block">
- <h3>4. 家长账号(JTCY → RY)</h3>
- <table>
- <tr>
- <th>家长RYID</th><th>姓名</th><th>账号ZH</th><th>手机GRDH</th><th>关系</th><th>负责家长</th>
- <th>类别</th><th>JLZTM</th><th>启用</th><th>微信绑定</th><th>末次登录</th>
- <th>岗位GWID</th><th>在用密码(前8位)</th><th>初始密码标记</th><th>密码更新时间</th><th>权限缓存rygw</th>
- </tr>
- <%
- for (Map<String, Object> p : parents) {
- long jzid = lng(p.get("jzid"));
- String lMm = cell(p, "l_mm");
- boolean initPwd = "Y".equalsIgnoreCase(cell(p, "l_sfcsmm"));
- boolean cacheOk = jzid > 0 && sauthCacheExists(jzid);
- String pName = cell(p, "p_xm");
- if (pName.isEmpty()) pName = cell(p, "jtcy_xm");
- String pPhone = cell(p, "p_grdh");
- if (pPhone.isEmpty()) pPhone = cell(p, "jtcy_grdh");
- %>
- <tr>
- <td class="mono"><%= esc(cell(p, "jzid")) %></td>
- <td><%= esc(pName) %></td>
- <td><%= esc(cell(p, "p_zh")) %></td>
- <td><%= esc(pPhone) %></td>
- <td><%= esc(cell(p, "jtgxm")) %></td>
- <td><%= yn(cell(p, "c_isfzjz")) %></td>
- <td><%= esc(cell(p, "p_rylbm")) %></td>
- <td><%= esc(cell(p, "p_jlztm")) %></td>
- <td><%= yn(cell(p, "p_sfqy")) %></td>
- <td><%= cell(p, "p_wbid2").isEmpty() ? "未绑定" : "已绑定" %></td>
- <td><%= dtm(p, "p_scdlsj") %></td>
- <td><%= esc(cell(p, "p_gwid")) %> <%= esc(cell(p, "p_gwmc")) %></td>
- <td class="mono"><%= lMm.isEmpty() ? "(无LSMM在用行)" : esc(lMm.substring(0, Math.min(8, lMm.length()))) %></td>
- <td><%= initPwd ? tag("tag-warn", "是") : "否" %></td>
- <td><%= dtm(p, "l_gxsj") %></td>
- <td><%= jzid == 0 ? tag("tag-info", "无家长") : (cacheOk ? tag("tag-ok", "存在") : tag("tag-warn", "缺失")) %></td>
- </tr>
- <%
- }
- if (parents.isEmpty()) {
- %>
- <tr><td colspan="16">无家长关系记录</td></tr>
- <%
- }
- %>
- </table>
- </div>
- <div class="block">
- <h3>5. 订阅记录(c##dc_py.pp_application)</h3>
- <table>
- <tr><th>申请号</th><th>学生</th><th>家长/手机</th><th>填写班级</th><th>套餐</th><th>金额(分)</th>
- <th>申请状态</th><th>同步状态</th><th>支付时间</th><th>PMS_RYID</th><th>PMS_JZID</th><th>渠道</th><th>交易号</th></tr>
- <%
- for (Map<String, Object> a : subs) {
- boolean okSync = "SUCCESS".equalsIgnoreCase(cell(a, "sync_status"));
- String ss = cell(a, "sync_status");
- %>
- <tr>
- <td class="mono"><%= esc(cell(a, "application_no")) %></td>
- <td><%= esc(cell(a, "student_name")) %></td>
- <td><%= esc(cell(a, "guardian_name")) %> <%= esc(cell(a, "guardian_mobile")) %></td>
- <td><%= esc(cell(a, "grade_name")) %> <%= esc(cell(a, "class_name")) %></td>
- <td><%= esc(cell(a, "selected_package_name")) %></td>
- <td><%= num(cell(a, "amount_paid_cent")) %></td>
- <td><%= esc(cell(a, "application_status")) %></td>
- <td><%= okSync ? tag("tag-ok", "SUCCESS") : tag("tag-warn", ss.isEmpty() ? "PENDING" : ss) %></td>
- <td><%= dtm(a, "paid_at") %></td>
- <td class="mono"><%= esc(cell(a, "pms_ryid")) %></td>
- <td class="mono"><%= esc(cell(a, "pms_jzid")) %></td>
- <td><%= esc(cell(a, "channel_code")) %></td>
- <td class="mono"><%= esc(cell(a, "pay_order_no")) %></td>
- </tr>
- <%
- }
- if (subs.isEmpty()) {
- %>
- <tr><td colspan="13">未匹配到订阅申请(按 学生RYID / 家长JZID / 家长手机号 三路匹配)</td></tr>
- <%
- }
- %>
- </table>
- <%
- if (!syncTasks.isEmpty()) {
- %>
- <div class="hint" style="margin-top:6px">同步任务(c##dc_py.pp_sync_task):</div>
- <table style="margin-top:4px">
- <tr><th>申请号</th><th>同步状态</th><th>说明NOTE</th><th>PMS_RYID</th><th>PMS_JZID</th><th>最后同步</th></tr>
- <%
- for (Map<String, Object> t : syncTasks) {
- %>
- <tr>
- <td class="mono"><%= esc(cell(t, "application_no")) %></td>
- <td><%= esc(cell(t, "sync_status")) %></td>
- <td><%= esc(cell(t, "note")) %></td>
- <td class="mono"><%= esc(cell(t, "pms_ryid")) %></td>
- <td class="mono"><%= esc(cell(t, "pms_jzid")) %></td>
- <td><%= dtm(t, "last_sync_at") %></td>
- </tr>
- <%
- }
- %>
- </table>
- <%
- }
- %>
- </div>
- <div class="block">
- <h3>6. 手机号重复检查</h3>
- <table>
- <tr><th>手机号</th><th>命中账号数</th><th>判定</th></tr>
- <%
- for (Map.Entry<String, Integer> e : phoneAccounts.entrySet()) {
- boolean dup = e.getValue() > 1;
- %>
- <tr>
- <td class="mono"><%= esc(e.getKey()) %></td>
- <td><%= e.getValue() %></td>
- <td><%= dup ? tag("tag-warn", "一号多账号,一键登录会提示“该手机号对应多个账号”") : tag("tag-ok", "正常") %></td>
- </tr>
- <%
- }
- if (phoneAccounts.isEmpty()) {
- %>
- <tr><td colspan="3">无手机号可比对</td></tr>
- <%
- }
- %>
- </table>
- <div class="hint" style="margin-top:6px">
- 命中账号数 = 在用人员的 账号/人员号/个人电话 命中数 ∪ 家长关系表中该手机对应的 JZID 数。
- </div>
- </div>
- </div>
- <%
- } catch (Exception ex) {
- %>
- <div class="card stu">
- <span class="tag tag-danger">该学生明细查询失败</span>
- <span class="mono"><%= esc(cell(s, "xm")) %> / RYID <%= esc(cell(s, "ryid")) %> / <%= esc(ex.toString()) %></span>
- </div>
- <%
- }
- }
- } catch (Exception e) {
- diag.append(e.getClass().getSimpleName()).append(": ").append(txt(e.getMessage()));
- }
- }
- if (conn != null) {
- try { conn.close(); } catch (Exception ignore) { }
- }
- %>
- <%
- if (diag.length() > 0) {
- %>
- <div class="card"><span class="tag tag-danger">明细查询异常</span> <span class="mono"><%= esc(diag.toString()) %></span></div>
- <%
- }
- %>
- </body>
- </html>
|