All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.openurp.web.action.api.MajorAction Maven / Gradle / Ivy

There is a newer version: 0.41.3
Show newest version
/*
 * OpenURP, Agile University Resource Planning Solution.
 *
 * Copyright © 2014, The OpenURP Software.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful.
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see .
 */
package org.openurp.web.action.api;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import jakarta.servlet.http.HttpServletResponse;

import org.beangle.commons.dao.query.builder.OqlBuilder;
import org.beangle.commons.lang.Arrays;
import org.beangle.commons.lang.Strings;
import org.openurp.base.edu.model.Major;
import org.openurp.base.edu.model.MajorJournal;
import org.openurp.edu.web.action.BaseAction;
import org.openurp.web.action.internal.ClazzGsonBuilderHelper;
import org.openurp.web.action.internal.ClazzGsonBuilderWorker;

import com.google.gson.Gson;

/**
 * 专业web service api
* entry: api/major
*/ public class MajorAction extends BaseAction { /** * Entry : api/major!get.action
* Accept params:
*
    *
  • levelIds
  • *
  • departmentIds
  • *
  • pageNo 页数
  • *
  • pageSize 页长
  • *
  • major.属性
  • *
* Return: json
* * @throws IOException */ public String json() throws IOException { Integer[] levelIds = Strings.splitToInt(get("levelIds")); Integer[] departmentIds = Strings.splitToInt(get("departmentIds")); String warnings = ""; if (Arrays.isEmpty(levelIds)) { warnings += "请先选择培养层次\n"; } if (Arrays.isEmpty(departmentIds)) { warnings += "请先选择上课院系"; } List majors = new ArrayList(); if (Strings.isBlank(warnings)) { OqlBuilder query = OqlBuilder.from(Major.class, "major"); query.where("major.project.id = :projectId", getIntId("project")) .where("exists(from major.journals md where md.depart.id in (:departIds))", departmentIds) .orderBy("major.code, major.name"); majors = entityDao.search(query); } Gson gson = new Gson(); String json = gson .toJson(ClazzGsonBuilderHelper.genGroupResult(majors, warnings, new ClazzGsonBuilderWorker() { public void dirtywork(Object object, Map groups) { Major major = (Major) object; for (MajorJournal md : major.getJournals()) { String groupName = md.getDepart().getName().toString(); if (groups.get(groupName) == null) { groups.put(groupName, new ArrayList>()); } List> entities = (List>) groups.get(groupName); Map entity = new TreeMap(); entity.put("id", major.getId()); entity.put("name", major.getName()); entity.put("code", major.getCode()); if (!entities.contains(entity)) { entities.add(entity); } } } })); HttpServletResponse response = getResponse(); response.setContentType("text/plain;charset=UTF-8"); response.getWriter().write(json); response.getWriter().close(); return null; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy