org.openurp.web.action.api.MajorAction Maven / Gradle / Ivy
/*
* 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
© 2015 - 2025 Weber Informatics LLC | Privacy Policy