You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

147 lines
5.1 KiB

package com.dsideal.newUniversityExamination.selectcourse.elective.model;
import java.util.List;
import com.alibaba.fastjson.JSONObject;
import com.dsideal.newUniversityExamination.util.COMMON;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;
public class ElectivesCourseModel extends Model<ElectivesCourseModel>{
/**
*
*/
private static final long serialVersionUID = 1L;
public static final ElectivesCourseModel dao = new ElectivesCourseModel();
/**
* 新增课程
* @param courseName
* @param sortId
* @return
* @author zms
*/
public String addCourseSortRelation(String courseName, String sortId,String courseId ) {
JSONObject resultJson=new JSONObject();
Record record = new Record();
record.set("course_name", courseName);
record.set("sort_id", sortId);
record.set("b_use", 1);
boolean flag = false ;
//新增课程
if(COMMON.isEmpty(courseId)){
//验证课程名称在此分类下是否重复
String sql = "select course_id from t_select_electives_course where 1=1 and sort_id = ? and course_name = ? and b_use=1 ";
List<Record> list = Db.find(sql,sortId,courseName);
if(!COMMON.isEmpty(list)){
resultJson.put("success", false);
resultJson.put("info", "课程名称重复!");
return resultJson.toJSONString();
}
flag = Db.save("t_select_electives_course", record);
}else{
//修改课程---验证课程名称在此分类下是否重复
String sql = "select course_id from t_select_electives_course where 1=1 and sort_id = ? and course_name = ? and course_id <> ? and b_use=1 ";
List<Record> list = Db.find(sql,sortId,courseName,courseId);
if(!COMMON.isEmpty(list)){
resultJson.put("success", false);
resultJson.put("info", "课程名称重复!");
return resultJson.toJSONString();
}
record.set("course_id", courseId);
flag = Db.update("t_select_electives_course", "course_id", record);
}
resultJson.put("success", flag);
if(flag){
resultJson.put("info", "操作成功");
}else{
resultJson.put("info", "操作失败");
}
return resultJson.toJSONString();
}
/**
* 批量删除课程
* @param courseArray
* @return
* @author zms
*/
public String batchDeleteCourse(String courseId) {
JSONObject resultJson = new JSONObject();
//验证此课程是否被使yong
String yzSql = " SELECT course_id from t_select_electives_plan_course WHERE course_id in("+courseId+")";
Record yzRecord = Db.findFirst(yzSql);
if(!COMMON.isEmpty(yzRecord)){
resultJson.put("success", false);
resultJson.put("info", "该课程在选课计划中被占用,请先将该课程从选课计划中删除!");
return resultJson.toJSONString();
}
String sql = "update t_select_electives_course set b_use =0 where course_id in ("+courseId+")";
int low = Db.update(sql);
if(low>0){
resultJson.put("success", true);
resultJson.put("info", "操作成功");
}else{
resultJson.put("success", false);
resultJson.put("info", "操作失败");
}
return resultJson.toJSONString();
}
//sql拼接查询条件
private String appendSql(Record university, String column, String rename,String type) {
String value = university.get(column);
String sql = "";
if (!COMMON.isEmpty(value)) {
if("1".equals(type)){
sql = " and " + rename + column + " like '%" + value + "%' ";
}else{
sql = " and " + rename + column + " = '" + value + "' ";
}
}
return sql;
}
/**
* 查询课程列表
* @param sourtId
* @param courseName
* @return
*/
public String getCourseList(String sourtId, String courseName,String pageNumber ,String pageSize,String bureauId) {
String totalSql = "SELECT course.course_id,course.course_name,course.sort_id,sort.sort_name ";
String sql = " from t_select_electives_course course join t_select_electives_sort sort on course.sort_id=sort.sort_id WHERE 1=1 and course.b_use =1 and sort.b_use =1 ";
Record record = new Record();
record.set("sort_id", sourtId);
record.set("course_name", courseName);
record.set("bureau_id", bureauId);
sql += appendSql(record, "sort_id", "course.", "");
sql += appendSql(record, "bureau_id", "sort.", "");
sql += appendSql(record, "course_name", "course.", "1");
sql += " ORDER BY sort.sort_id,course.course_id ";
Page<Record> pageRecord = Db.paginate(
Integer.parseInt(String.valueOf(pageNumber)),
Integer.parseInt(String.valueOf(pageSize)),
totalSql, sql);
List<Record> list = pageRecord.getList();
JSONObject resultJson = new JSONObject();
resultJson.put("success", true);
resultJson.put("info", "操作成功");
resultJson.put("result_list", COMMON.convertListRecord2(list));
resultJson.put("page_number", pageRecord.getPageNumber());
resultJson.put("page_size", pageRecord.getPageSize());
resultJson.put("total_page", pageRecord.getTotalPage());
resultJson.put("total_row", pageRecord.getTotalRow());
return resultJson.toJSONString();
}
}