|
|
@@ -0,0 +1,269 @@
|
|
|
+package biz.bjpj;
|
|
|
+
|
|
|
+import base.po.HjjlPo;
|
|
|
+import base.po.HjjlcyPo;
|
|
|
+import com.google.gson.Gson;
|
|
|
+import jakarta.servlet.http.HttpServletRequest;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.apache.logging.log4j.LogManager;
|
|
|
+import org.apache.logging.log4j.Logger;
|
|
|
+import ss.AppB;
|
|
|
+import ss.bpm.Bpm;
|
|
|
+import ss.bpm.BpmAddRunB;
|
|
|
+import ss.bpm.BpmC;
|
|
|
+import ss.bpm.BpmU;
|
|
|
+import ss.db.Db;
|
|
|
+import ss.db.DbU;
|
|
|
+import ss.db.SqlCmd;
|
|
|
+import ss.db.impl.SqPo;
|
|
|
+import ss.obj.ObjB;
|
|
|
+import ss.serv.Serv;
|
|
|
+import ss.serv.ServU;
|
|
|
+import ss.user.UserRunB;
|
|
|
+import ss.user.UserU;
|
|
|
+
|
|
|
+import java.io.Writer;
|
|
|
+import java.sql.Timestamp;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.time.format.DateTimeParseException;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.LinkedHashMap;
|
|
|
+import java.util.LinkedHashSet;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Set;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 学校获奖记录小程序专用服务。
|
|
|
+ */
|
|
|
+public class XxhjjlMpServ extends Serv {
|
|
|
+
|
|
|
+ private static final Logger log4j = LogManager.getLogger(XxhjjlMpServ.class);
|
|
|
+ private static final DateTimeFormatter DATE_FMT =
|
|
|
+ DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
+ private static final int HJXZ_PERSONAL = 1;
|
|
|
+ private static final int HJXZ_COLLECTIVE = 2;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存个人或集体学校获奖记录,并启动既有增加流程。
|
|
|
+ */
|
|
|
+ @SuppressWarnings("unused")
|
|
|
+ public void saveByA() throws Exception {
|
|
|
+ HttpServletRequest request = super.req;
|
|
|
+ super.resp.setCharacterEncoding("UTF-8");
|
|
|
+ super.resp.setContentType("application/json;charset=UTF-8");
|
|
|
+ Writer writer = super.resp.getWriter();
|
|
|
+ Gson gson = new Gson();
|
|
|
+
|
|
|
+ try (Db db = Db.makeConn()) {
|
|
|
+ UserRunB user = UserU.rdUserByReq(request);
|
|
|
+ if (user == null)
|
|
|
+ throw new IllegalArgumentException("登录状态已失效,请退出小程序重新进入");
|
|
|
+
|
|
|
+ int hjxz = rdIntParam(request, "hjxz", true);
|
|
|
+ if (hjxz != HJXZ_PERSONAL && hjxz != HJXZ_COLLECTIVE)
|
|
|
+ throw new IllegalArgumentException("获奖性质参数错误");
|
|
|
+ int hjlbm = rdIntParam(request, "hjlbm", true);
|
|
|
+ LocalDate hjrq = rdDate(request, "hjrq");
|
|
|
+ String description = StringUtils.trimToEmpty(request.getParameter("ms"));
|
|
|
+ Long fjid = rdLongObj(request.getParameter("fjid"));
|
|
|
+ Map<String, Object> awardType = rdAwardType(db, hjlbm);
|
|
|
+
|
|
|
+ List<Participant> participants = new ArrayList<>();
|
|
|
+ long primaryBjid;
|
|
|
+ Long personalRyid = null;
|
|
|
+ if (hjxz == HJXZ_PERSONAL) {
|
|
|
+ long ryid = rdLongParam(request, "ryid", true);
|
|
|
+ primaryBjid = rdStudentClass(db, ryid);
|
|
|
+ personalRyid = ryid;
|
|
|
+ if (rdFloat(awardType.get("bjf")) <= 0F)
|
|
|
+ throw new IllegalArgumentException("该获奖类别未配置个人分值");
|
|
|
+ } else {
|
|
|
+ if (rdFloat(awardType.get("jtbjf")) <= 0F)
|
|
|
+ throw new IllegalArgumentException("该获奖类别未配置集体分值");
|
|
|
+ for (long ryid : rdLongList(request.getParameter("ryids"))) {
|
|
|
+ long bjid = rdStudentClass(db, ryid);
|
|
|
+ participants.add(new Participant(ryid, bjid));
|
|
|
+ }
|
|
|
+ if (participants.isEmpty())
|
|
|
+ throw new IllegalArgumentException("集体获奖至少需要一名参与学生");
|
|
|
+ primaryBjid = participants.get(0).bjid;
|
|
|
+ }
|
|
|
+
|
|
|
+ HjjlPo award = new HjjlPo();
|
|
|
+ award.setBjid(primaryBjid);
|
|
|
+ award.setRyid(personalRyid);
|
|
|
+ award.setHjlbm(hjlbm);
|
|
|
+ award.setHjxz(hjxz);
|
|
|
+ award.setHjrq(java.sql.Date.valueOf(hjrq));
|
|
|
+ award.setMs(description);
|
|
|
+ award.setFjid(fjid);
|
|
|
+
|
|
|
+ Set<String> fields = new LinkedHashSet<>();
|
|
|
+ fields.add("bjid");
|
|
|
+ fields.add("ryid");
|
|
|
+ fields.add("hjlbm");
|
|
|
+ fields.add("hjxz");
|
|
|
+ fields.add("hjrq");
|
|
|
+ fields.add("ms");
|
|
|
+ fields.add("fjid");
|
|
|
+ fields.add("jlztm");
|
|
|
+ fields.add("cjryid");
|
|
|
+ fields.add("glryid");
|
|
|
+ fields.add("glbmid");
|
|
|
+ DbU.wrSsFieldByPo(award, fields, user, false);
|
|
|
+ long hjjlid = db.doInsPo(award, fields);
|
|
|
+
|
|
|
+ if (hjxz == HJXZ_COLLECTIVE)
|
|
|
+ insertParticipants(db, hjjlid, participants, user);
|
|
|
+
|
|
|
+ ObjB vo = AppB.objMap.get("xxhjjl");
|
|
|
+ if (vo == null)
|
|
|
+ throw new IllegalStateException("学校获奖对象未配置");
|
|
|
+ BpmU.saveSq(null, award, vo, BpmC.CHG_addType, null,
|
|
|
+ user.ryid, null, db, request);
|
|
|
+ db.commit();
|
|
|
+
|
|
|
+ boolean bpmStarted = true;
|
|
|
+ String warnMsg = null;
|
|
|
+ try {
|
|
|
+ SqPo sq = new SqPo();
|
|
|
+ sq.setDxm("xxhjjl");
|
|
|
+ sq.setMc("移动端提交学校获奖记录(" + hjrq + ")");
|
|
|
+ Bpm.doStartBpm("xxhjjl_zj", award, sq,
|
|
|
+ new LinkedHashMap<>(), new BpmAddRunB(), user.ryid,
|
|
|
+ request, super.resp);
|
|
|
+ } catch (Exception e) {
|
|
|
+ bpmStarted = false;
|
|
|
+ warnMsg = "获奖记录已保存,但审批流程启动失败";
|
|
|
+ log4j.error("XxhjjlMpServ.saveByA() 启动流程失败,hjjlid="
|
|
|
+ + hjjlid, e);
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, Object> data = new LinkedHashMap<>();
|
|
|
+ data.put("hjjlid", hjjlid);
|
|
|
+ data.put("hjxz", hjxz);
|
|
|
+ data.put("bpmStarted", bpmStarted);
|
|
|
+ data.put("warnMsg", warnMsg);
|
|
|
+ ServU.wrOkDataByWriter(data, writer, gson);
|
|
|
+ } catch (DateTimeParseException e) {
|
|
|
+ ServU.wrErrMsgByWriter(null, "获奖日期格式错误", writer, gson);
|
|
|
+ } catch (IllegalArgumentException e) {
|
|
|
+ ServU.wrErrMsgByWriter(null, e.getMessage(), writer, gson);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log4j.error("XxhjjlMpServ.saveByA() 异常", e);
|
|
|
+ ServU.wrErrMsgByWriter(null, "学校获奖记录提交失败", writer, gson);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void insertParticipants(
|
|
|
+ Db db, long hjjlid, List<Participant> participants, UserRunB user)
|
|
|
+ throws Exception {
|
|
|
+ Set<Long> seen = new LinkedHashSet<>();
|
|
|
+ for (Participant participant : participants) {
|
|
|
+ if (!seen.add(participant.ryid))
|
|
|
+ continue;
|
|
|
+ HjjlcyPo member = new HjjlcyPo();
|
|
|
+ member.setHjjlid(hjjlid);
|
|
|
+ member.setRyid(participant.ryid);
|
|
|
+ member.setBjid(participant.bjid);
|
|
|
+ member.setJlztm(51);
|
|
|
+ member.setCjryid(user.ryid);
|
|
|
+ member.setGlryid(user.ryid);
|
|
|
+ member.setGlbmid(user.bmid);
|
|
|
+ Set<String> fields = new LinkedHashSet<>();
|
|
|
+ fields.add("hjjlid");
|
|
|
+ fields.add("ryid");
|
|
|
+ fields.add("bjid");
|
|
|
+ fields.add("jlztm");
|
|
|
+ fields.add("cjryid");
|
|
|
+ fields.add("glryid");
|
|
|
+ fields.add("glbmid");
|
|
|
+ db.doInsPo(member, fields);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Map<String, Object> rdAwardType(Db db, int hjlbm)
|
|
|
+ throws Exception {
|
|
|
+ SqlCmd sqlc = new SqlCmd(
|
|
|
+ "select MC \"mc\",HJLBM \"hjlbm\",BJJF \"bjf\","
|
|
|
+ + "JTBJJF \"jtbjf\" from HJLB where HJLBM=:hjlbm");
|
|
|
+ sqlc.wrIntParm("hjlbm", hjlbm);
|
|
|
+ Map<String, Object> row = db.doSelMapByC(sqlc);
|
|
|
+ if (row == null || row.isEmpty())
|
|
|
+ throw new IllegalArgumentException("获奖类别不存在");
|
|
|
+ return row;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static long rdStudentClass(Db db, long ryid) throws Exception {
|
|
|
+ SqlCmd sqlc = new SqlCmd(
|
|
|
+ "select count(*) CNT,min(BJID) BJID from BJCY"
|
|
|
+ + " where RYID=:ryid and JLZTM in(22,25,51)"
|
|
|
+ + " and nvl(SFBY,0)=0");
|
|
|
+ sqlc.wrLongParm("ryid", ryid);
|
|
|
+ db.doSelByC(sqlc);
|
|
|
+ int count = db.rdIntCol("cnt");
|
|
|
+ if (count == 0)
|
|
|
+ throw new IllegalArgumentException("参与学生当前没有有效班级");
|
|
|
+ if (count > 1)
|
|
|
+ throw new IllegalArgumentException("参与学生存在多个有效班级,请先核对学籍");
|
|
|
+ return db.rdLongCol("bjid");
|
|
|
+ }
|
|
|
+
|
|
|
+ private static LocalDate rdDate(HttpServletRequest request, String name) {
|
|
|
+ String value = StringUtils.trimToNull(request.getParameter(name));
|
|
|
+ if (value == null)
|
|
|
+ throw new IllegalArgumentException("请选择获奖日期");
|
|
|
+ return LocalDate.parse(value, DATE_FMT);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static List<Long> rdLongList(String text) {
|
|
|
+ List<Long> values = new ArrayList<>();
|
|
|
+ for (String part : StringUtils.defaultString(text).split(",")) {
|
|
|
+ String value = StringUtils.trimToNull(part);
|
|
|
+ if (value != null)
|
|
|
+ values.add(Long.parseLong(value));
|
|
|
+ }
|
|
|
+ return values;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static long rdLongParam(
|
|
|
+ HttpServletRequest request, String name, boolean required) {
|
|
|
+ String value = StringUtils.trimToNull(request.getParameter(name));
|
|
|
+ if (value == null) {
|
|
|
+ if (required)
|
|
|
+ throw new IllegalArgumentException(name + "不能为空");
|
|
|
+ return 0L;
|
|
|
+ }
|
|
|
+ return Long.parseLong(value);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static int rdIntParam(
|
|
|
+ HttpServletRequest request, String name, boolean required) {
|
|
|
+ long value = rdLongParam(request, name, required);
|
|
|
+ return (int) value;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Long rdLongObj(String value) {
|
|
|
+ String text = StringUtils.trimToNull(value);
|
|
|
+ return text == null ? null : Long.valueOf(text);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static float rdFloat(Object value) {
|
|
|
+ if (value == null)
|
|
|
+ return 0F;
|
|
|
+ String text = StringUtils.trimToNull(String.valueOf(value));
|
|
|
+ return text == null ? 0F : Float.parseFloat(text);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static final class Participant {
|
|
|
+ final long ryid;
|
|
|
+ final long bjid;
|
|
|
+
|
|
|
+ Participant(long ryid, long bjid) {
|
|
|
+ this.ryid = ryid;
|
|
|
+ this.bjid = bjid;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|