Просмотр исходного кода

fix(starclass): enforce report batch period

harper 3 недель назад
Родитель
Сommit
99e318b97a
1 измененных файлов с 46 добавлено и 10 удалено
  1. 46 10
      src/biz/bj/BjStarClassMpServ.java

+ 46 - 10
src/biz/bj/BjStarClassMpServ.java

@@ -270,14 +270,19 @@ public class BjStarClassMpServ extends Serv {
 
         try (Db db = Db.makeConn()) {
             UserRunB user = requireUser(request);
-            ClassInfo selected = pcReport
-                    ? requireReportClass(db,
-                    rdLongParam(request, "bjid", true),
-                    rdLongParam(request, "jdid", true))
-                    : requireTeacherClass(db, user.ryid,
-                    rdLongParam(request, "bjid", false));
+            ClassInfo selected;
+            YearMonth reportMonth = null;
+            if (pcReport) {
+                long bjid = rdLongParam(request, "bjid", true);
+                long jdid = rdLongParam(request, "jdid", true);
+                selected = requireReportClass(db, bjid, jdid);
+                reportMonth = rdReportBatchMonth(db, jdid);
+            } else {
+                selected = requireTeacherClass(db, user.ryid,
+                        rdLongParam(request, "bjid", false));
+            }
             Map<String, Object> data = buildDetailData(db, selected,
-                    request);
+                    request, reportMonth);
             ServU.wrOkDataByWriter(data, writer, gson);
         } catch (DateTimeParseException e) {
             ServU.wrErrMsgByWriter(null, "日期格式错误", writer, gson);
@@ -292,7 +297,8 @@ public class BjStarClassMpServ extends Serv {
 
 
     private static Map<String, Object> buildDetailData(
-            Db db, ClassInfo selected, HttpServletRequest request)
+            Db db, ClassInfo selected, HttpServletRequest request,
+            YearMonth reportMonth)
             throws Exception {
         String mode = StringUtils.defaultIfBlank(
                 request.getParameter("mode"), "dayItem");
@@ -302,10 +308,12 @@ public class BjStarClassMpServ extends Serv {
                     request.getParameter("kind"), "regular");
             long recordId = rdLongParam(request, "id", true);
             if ("adjustment".equals(kind))
-                return rdAdjustmentTrace(db, selected, recordId);
+                return rdAdjustmentTrace(db, selected, recordId,
+                        reportMonth);
             LocalDate day = rdDate(request, "date");
             if (day.isAfter(LocalDate.now(CN_ZONE)))
                 throw new IllegalArgumentException("不能查询未来日期");
+            ensureReportMonth(reportMonth, YearMonth.from(day));
             CategoryDef category = requireCategory(StringUtils.trimToNull(
                     request.getParameter("category")));
             String source = StringUtils.defaultIfBlank(
@@ -325,6 +333,7 @@ public class BjStarClassMpServ extends Serv {
 
         if ("bonus".equals(mode) || "deduction".equals(mode)) {
             YearMonth month = rdMonth(request);
+            ensureReportMonth(reportMonth, month);
             List<Adjustment> adjustments = rdAdjustments(
                     db, selected.bjid, month);
             List<Adjustment> selectedAdjustments = new ArrayList<>();
@@ -341,6 +350,7 @@ public class BjStarClassMpServ extends Serv {
             monthText = month.format(MONTH_FMT);
         } else if ("monthCategory".equals(mode)) {
             YearMonth month = rdMonth(request);
+            ensureReportMonth(reportMonth, month);
             categoryCode = StringUtils.trimToNull(
                     request.getParameter("category"));
             CategoryDef category = requireCategory(categoryCode);
@@ -352,6 +362,7 @@ public class BjStarClassMpServ extends Serv {
             LocalDate day = rdDate(request, "date");
             if (day.isAfter(LocalDate.now(CN_ZONE)))
                 throw new IllegalArgumentException("不能查询未来日期");
+            ensureReportMonth(reportMonth, YearMonth.from(day));
             categoryCode = StringUtils.trimToNull(
                     request.getParameter("category"));
             CategoryDef category = requireCategory(categoryCode);
@@ -481,6 +492,25 @@ public class BjStarClassMpServ extends Serv {
     }
 
 
+    private static YearMonth rdReportBatchMonth(Db db, long jdid)
+            throws Exception {
+        SqlCmd sqlc = new SqlCmd(
+                "select NDY from XJB_JD where XJB_JDID=:jdid and ZT=5");
+        sqlc.wrLongParm("jdid", jdid);
+        db.doSelByC(sqlc);
+        if (db.rowNum == 0)
+            throw new IllegalArgumentException("月结批次不存在或未发布");
+        return YearMonth.parse(db.rdStrCol("ndy"), MONTH_FMT);
+    }
+
+
+    private static void ensureReportMonth(YearMonth reportMonth,
+                                          YearMonth requestedMonth) {
+        if (reportMonth != null && !reportMonth.equals(requestedMonth))
+            throw new IllegalArgumentException("明细月份不属于当前月结批次");
+    }
+
+
     private static ScoreBook rdScoreBook(Db db, List<ClassInfo> classes,
                                          MonthPeriod period) throws Exception {
         ScoreBook book = new ScoreBook();
@@ -1717,7 +1747,8 @@ public class BjStarClassMpServ extends Serv {
 
 
     private static Map<String, Object> rdAdjustmentTrace(
-            Db db, ClassInfo cls, long ledgerId) throws Exception {
+            Db db, ClassInfo cls, long ledgerId, YearMonth reportMonth)
+            throws Exception {
         SqlCmd ledgerCmd = new SqlCmd(
                 "select j.XJB_JFJLID,j.NDY,j.FSSJ,j.JFLX,j.JFZ,j.MC,j.MS,"
                         + "j.LYLX,j.LYID,j.LYLB,j.RYID,r.XM RYXM"
@@ -1731,6 +1762,11 @@ public class BjStarClassMpServ extends Serv {
         if (ledgerRows == null || ledgerRows.isEmpty())
             throw new IllegalArgumentException("增扣分记录不存在或已不可查看");
         Map<String, Object> ledger = ledgerRows.get(0);
+        if (reportMonth != null) {
+            YearMonth ledgerMonth = YearMonth.parse(
+                    rdStr(ledger.get("ndy")), MONTH_FMT);
+            ensureReportMonth(reportMonth, ledgerMonth);
+        }
         String sourceType = defaultText(ledger.get("lylx"), "");
         long sourceId = rdLong(ledger.get("lyid"));
         if (XjbJfServ.LYLX_AWARD.equals(sourceType))