org.openurp.web.action.api.DirectionAction 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.Direction;
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 DirectionAction extends BaseAction {
/**
* Entry : api/direction!get.action
* Accept params:
*
* - majorIds
* - departmentIds
* - pageNo 页数
* - pageSize 页长
* - direction.属性
*
* Return: json
*
* @throws IOException
*/
public String json() throws IOException {
Integer[] majorIds = Strings.splitToInt(get("majorIds"));
Integer[] departmentIds = Strings.splitToInt(get("departmentIds"));
String warnings = "";
if (Arrays.isEmpty(majorIds)) {
warnings += "请先选择专业";
}
if (Strings.isNotBlank(warnings)) {
put("warnings", warnings);
return forward("directionsJSON");
}
List directions = new ArrayList();
if (Strings.isBlank(warnings)) {
OqlBuilder query = OqlBuilder.from(Direction.class, "direction");
query.where("direction.major.project.id = :projectId", getIntId("project"))
.where("direction.major.id in (:majorIds)", majorIds).orderBy("direction.code, direction.name");
if (null != departmentIds && departmentIds.length > 0) {
query.where("exists(from direction.journals dd where dd.depart.id in (:departIds))", departmentIds);
}
directions = entityDao.search(query);
}
Gson gson = new Gson();
String json = gson
.toJson(ClazzGsonBuilderHelper.genGroupResult(directions, warnings, new ClazzGsonBuilderWorker() {
public void dirtywork(Object object, Map groups) {
Direction rawEntity = (Direction) object;
String groupName = rawEntity.getMajor().getName();
if (groups.get(groupName) == null) {
groups.put(groupName, new ArrayList
© 2015 - 2025 Weber Informatics LLC | Privacy Policy