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.
234 lines
9.5 KiB
234 lines
9.5 KiB
package com.dsideal.newUniversityExamination.selectcourse.elective.model;
|
|
|
|
import java.io.IOException;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.dsideal.newUniversityExamination.util.BorrowUtil;
|
|
import com.dsideal.newUniversityExamination.util.COMMON;
|
|
import com.dsideal.newUniversityExamination.util.Constant;
|
|
import com.dsideal.newUniversityExamination.util.ToolsUtil;
|
|
import com.dsideal.util.HttpClientUtil;
|
|
import com.jfinal.plugin.activerecord.Db;
|
|
import com.jfinal.plugin.activerecord.Model;
|
|
import com.jfinal.plugin.activerecord.Record;
|
|
|
|
public class ElectivesApplyModel extends Model<ElectivesApplyModel>{
|
|
|
|
/**
|
|
*
|
|
*/
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
public static final ElectivesApplyModel dao = new ElectivesApplyModel();
|
|
|
|
/**
|
|
* 查询学生选修志愿
|
|
* @param string
|
|
* @return
|
|
*/
|
|
public String getStudentElectiveApply(String personId , String type ,String classId,String bureauId) {
|
|
JSONObject resultJson = new JSONObject();
|
|
//查询当前学期
|
|
String getUrlRole = Constant.url+"/dsideal_yy/xx/getCurrentTerm";
|
|
String result = "";
|
|
try {
|
|
result = (String) HttpClientUtil.httpGetReq(getUrlRole);
|
|
System.out.println("[RESPONSE] POST WITHOUT COOKIE ===> " + result);
|
|
} catch (IOException e) {
|
|
// TODO Auto-generated catch block
|
|
e.printStackTrace();
|
|
}
|
|
JSONObject jsonOb=JSONObject.parseObject(result);
|
|
String xqId=String.valueOf(jsonOb.get("XQ_ID")) ;
|
|
//判断学生是否在当前选科计划内
|
|
String planId = "" ;
|
|
String planSql = "SELECT plan_id,plan_name,class_ids,status from t_select_electives_plan WHERE status =2 and bureau_id= ? and xq = ?";
|
|
List<Record> planList = Db.find(planSql,bureauId,xqId);
|
|
for (Record eachRecord : planList ) {
|
|
String classIds = eachRecord.get("class_ids");
|
|
if(ToolsUtil.arrayIncludeStr(classIds, classId)){
|
|
planId = String.valueOf(eachRecord.get("plan_id"));
|
|
break ;
|
|
}
|
|
}
|
|
if(COMMON.isEmpty(planId)){
|
|
resultJson.put("plan_id", "");
|
|
resultJson.put("exist", false);
|
|
}else{
|
|
resultJson.put("plan_id", Integer.parseInt(planId));
|
|
resultJson.put("exist", true);
|
|
}
|
|
//查询当前正在进行的选课计划
|
|
List<Record> resltList = new ArrayList<>();
|
|
if("0".equals(type)){
|
|
if(COMMON.isEmpty(planId)){
|
|
List<Record> list = new ArrayList<>();
|
|
resultJson.put("success", true);
|
|
resultJson.put("info", "操作成功");
|
|
resultJson.put("result_list",COMMON.convertListRecord2(list));
|
|
return resultJson.toJSONString();
|
|
}else{
|
|
String sql = " SELECT p.plan_id,p.plan_name,p.status as plan_status ,a.person_id,course.course_id,course.course_name,pc.plan_course_id,a.status apply_status from t_select_electives_apply a"
|
|
+ " join t_select_electives_plan_course pc on pc.plan_course_id = a.plan_course_id "
|
|
+ " join t_select_electives_course course on course.course_id = pc.course_id and course.b_use =1 join t_select_electives_plan p on p.plan_id = a.plan_id and p.bureau_id=? "
|
|
+ " WHERE 1=1 and a.person_id = ? and p.plan_id = ? ORDER BY p.status ";
|
|
resltList = Db.find(sql,bureauId,personId,planId);
|
|
if(COMMON.isEmpty(resltList)){
|
|
List<Record> list = new ArrayList<>();
|
|
resultJson.put("success", true);
|
|
resultJson.put("info", "操作成功");
|
|
resultJson.put("result_list",COMMON.convertListRecord2(list));
|
|
return resultJson.toJSONString();
|
|
}
|
|
}
|
|
}else{
|
|
//查询历史的选课计划
|
|
String sql = " SELECT p.plan_id,p.plan_name,p.status as plan_status ,a.person_id,course.course_id,course.course_name,pc.plan_course_id,a.status apply_status from t_select_electives_plan_class c "
|
|
+" join t_select_electives_plan p on p.plan_id = c.plan_id and p.status <> 1 "
|
|
+" left join t_select_electives_apply a on a.plan_id = p.plan_id and a.person_id = ? "
|
|
+" left join t_select_electives_plan_course pc on pc.plan_course_id = a.plan_course_id "
|
|
+" left join t_select_electives_course course on course.course_id = pc.course_id and course.b_use =1 "
|
|
+" WHERE c.class_id = ? and c.b_use =1 ORDER BY p.plan_id DESC ";
|
|
resltList = Db.find(sql,personId,classId);
|
|
|
|
}
|
|
|
|
resultJson.put("success", true);
|
|
resultJson.put("info", "操作成功");
|
|
resultJson.put("result_list",COMMON.convertListRecord2(resltList));
|
|
return resultJson.toJSONString();
|
|
}
|
|
|
|
/**
|
|
* 学生选择志愿
|
|
* @param personId
|
|
* @param planCourseId
|
|
* @param classId
|
|
* @return
|
|
* @author zms
|
|
* 2018-7-25
|
|
*/
|
|
public String addStudentApplyCourse(String personId, String planCourseId,String planId,String isOver) {
|
|
//验证是否可以选择
|
|
boolean yzflag =yzStudentSelectCourse(personId, planCourseId,planId,isOver);
|
|
JSONObject resultJson = new JSONObject();
|
|
if(!yzflag){
|
|
resultJson.put("success", yzflag);
|
|
resultJson.put("info", "操作失败");
|
|
return resultJson.toJSONString();
|
|
}
|
|
Record record = new Record();
|
|
record.set("person_id", personId);
|
|
record.set("plan_course_id", planCourseId);
|
|
record.set("plan_id", planId);
|
|
if("1".equals(isOver)){
|
|
record.set("status", 2);
|
|
}else{
|
|
record.set("status", 1);
|
|
}
|
|
boolean flag = false;
|
|
String sql = "select * from t_select_electives_apply where plan_id = ? and person_id = ? ";
|
|
Record recordApply = Db.findFirst(sql,planId,personId);
|
|
if(COMMON.isEmpty(recordApply)){
|
|
flag = Db.save("t_select_electives_apply", record);
|
|
}else{
|
|
String status = String.valueOf(recordApply.get("status"));
|
|
if("1".equals(isOver)){
|
|
status = "2" ;
|
|
}else{
|
|
status = "1";
|
|
}
|
|
String updSql = "update t_select_electives_apply set plan_course_id=?,status =? where plan_id = ? and person_id = ? ";
|
|
int i = Db.update(updSql,planCourseId,status,planId,personId);
|
|
flag = i>0;
|
|
}
|
|
|
|
resultJson.put("success", flag);
|
|
if(flag){
|
|
resultJson.put("info", "操作成功");
|
|
}else{
|
|
resultJson.put("info", "操作失败");
|
|
}
|
|
return resultJson.toJSONString();
|
|
}
|
|
public boolean yzStudentSelectCourse(String personId ,String planCourseId,String planId,String isOver){
|
|
boolean flag = false ;
|
|
//判断任务是否结束,学生登录
|
|
if(!"1".equals(isOver)){
|
|
String taskOver = "SELECT plan_id,plan_name,status from t_select_electives_plan WHERE status =2 and plan_id = ? ";
|
|
Record recordTask = Db.findFirst(taskOver,planId);
|
|
if(COMMON.isEmpty(recordTask)){
|
|
return flag ;
|
|
}
|
|
}
|
|
JSONObject jsonXb = BorrowUtil.getPersonInfo(personId, "6");
|
|
String xbName = String.valueOf(jsonXb.get("sex"));
|
|
String sql = "select * from t_select_electives_plan_course WHERE plan_course_id =? and b_use =1 ";
|
|
Record courseRecord = Db.findFirst(sql,planCourseId);
|
|
if(COMMON.isEmpty(courseRecord)){
|
|
return flag ;
|
|
}
|
|
int upper = courseRecord.get("upper");
|
|
String personBoy = " SELECT count(*) as count from t_select_electives_apply a join t_base_student s on a.person_id = s.student_id and s.b_use =1 WHERE s.xb_name='男' and a.status <> 3 and a.plan_course_id=?";
|
|
Record numRecord = Db.findFirst(personBoy,planCourseId);
|
|
String count = String.valueOf(numRecord.get("count"));//已经选了的男生数
|
|
|
|
String personGril = " SELECT count(*) as count from t_select_electives_apply a join t_base_student s on a.person_id = s.student_id and s.b_use =1 WHERE s.xb_name<>'男' and a.status <> 3 and a.plan_course_id=?";
|
|
Record numGrilRecord = Db.findFirst(personGril,planCourseId);
|
|
String countGril = String.valueOf(numGrilRecord.get("count"));//已经选了的女生数
|
|
//查询选课课程的人数(男,女)
|
|
Long overNUmber ;
|
|
if("男".equals(xbName)){
|
|
if(COMMON.isEmpty(courseRecord.get("upper_boy"))){
|
|
overNUmber =(long) upper - (Integer.parseInt(count)+Integer.parseInt(countGril)) ;
|
|
}else{
|
|
int upperBoy = Integer.parseInt(String.valueOf(courseRecord.get("upper_boy"))) ;
|
|
overNUmber = Math.round(((double)upper*(double)upperBoy)/100)- Integer.parseInt(count);
|
|
}
|
|
}else{
|
|
if(COMMON.isEmpty(courseRecord.get("upper_boy"))){
|
|
overNUmber =(long) upper - (Integer.parseInt(count)+Integer.parseInt(countGril)) ;
|
|
}else{
|
|
int upperBoy = Integer.parseInt(String.valueOf(courseRecord.get("upper_boy"))) ;
|
|
overNUmber = (upper-Math.round(((double)upper*(double)upperBoy)/100))- Integer.parseInt(countGril);
|
|
}
|
|
}
|
|
if(overNUmber>0){
|
|
flag = true ;
|
|
}
|
|
|
|
return flag ;
|
|
}
|
|
|
|
/**
|
|
* 改变学生志愿状态
|
|
* @param planId
|
|
* @param personId
|
|
* @return
|
|
*/
|
|
public String delStudentStatus(String planId, String personId,String status) {
|
|
// 1.删除 3.选科志愿失败
|
|
int low = 0 ;
|
|
if("1".equals(status)){
|
|
String sql = " DELETE from t_select_electives_apply WHERE plan_id = ? and person_id in ("+personId+") ";
|
|
low = Db.update(sql,planId);
|
|
}else if("3".equals(status)||"2".equals(status)){
|
|
String sql = " UPDATE t_select_electives_apply set status = ? WHERE plan_id = ? and person_id in ("+personId+") ";
|
|
low = Db.update(sql,status,planId);
|
|
}
|
|
JSONObject resultJson = new JSONObject();
|
|
if(low > 0){
|
|
resultJson.put("success", true);
|
|
resultJson.put("info", "操作成功");
|
|
}else{
|
|
resultJson.put("success", false);
|
|
resultJson.put("info", "操作失败");
|
|
}
|
|
return resultJson.toJSONString();
|
|
}
|
|
|
|
|
|
}
|