|
|
|
|
package com.dsideal.FengHuang.Yp.Model;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.date.DateTime;
|
|
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
|
|
import cn.hutool.core.util.IdcardUtil;
|
|
|
|
|
import com.jfinal.plugin.activerecord.Db;
|
|
|
|
|
import com.jfinal.plugin.activerecord.Record;
|
|
|
|
|
|
|
|
|
|
import java.util.Calendar;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
public class YpModel {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:获取当前任务名称
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public Record getCurrentTaskInfo() {
|
|
|
|
|
String sql = "select task_id,task_name,is_run from t_yp_task where b_use=1";
|
|
|
|
|
return Db.findFirst(sql);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:获取指定任务的开启班型及人数限制
|
|
|
|
|
*/
|
|
|
|
|
public List<Record> getTaskLimit(int task_id) {
|
|
|
|
|
String sql = "select * from t_yp_task_bx_limit where task_id=?";
|
|
|
|
|
return Db.find(sql, task_id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<Record> getTaskApplyCount(int task_id) {
|
|
|
|
|
String sql = "select bx_id from t_yp_task_bx_limit as t1 where t1.task_id=?";
|
|
|
|
|
List<Record> list = Db.find(sql, task_id);
|
|
|
|
|
|
|
|
|
|
for (Record record : list) {
|
|
|
|
|
int bx_id = record.getInt("bx_id");
|
|
|
|
|
sql = "select count(*) as count from t_yp_record as t2 where t2.task_id=? and t2.bx_id=?";
|
|
|
|
|
Record r1 = Db.findFirst(sql, task_id, bx_id);
|
|
|
|
|
record.set("apply_count", r1.getInt("count"));
|
|
|
|
|
}
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:增加任务
|
|
|
|
|
*/
|
|
|
|
|
public void addTask(String task_name) {
|
|
|
|
|
Record record = new Record();
|
|
|
|
|
record.set("task_name", task_name);
|
|
|
|
|
record.set("create_time", DateTime.now());
|
|
|
|
|
record.set("b_use", 0);
|
|
|
|
|
record.set("is_run", 0);
|
|
|
|
|
Db.save("t_yp_task", "task_id", record);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:修改任务
|
|
|
|
|
*/
|
|
|
|
|
public void updateTask(int task_id, String task_name) {
|
|
|
|
|
String sql = "update t_yp_task set task_name=? where task_id=?";
|
|
|
|
|
Db.update(sql, task_name, task_id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:删除任务
|
|
|
|
|
*
|
|
|
|
|
* @param task_id
|
|
|
|
|
*/
|
|
|
|
|
public void delTask(int task_id) {
|
|
|
|
|
String sql = "update t_yp_task set b_use=0 where task_id=?";
|
|
|
|
|
Db.update(sql, task_id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:启动任务
|
|
|
|
|
*
|
|
|
|
|
* @param task_id
|
|
|
|
|
*/
|
|
|
|
|
public void startTask(int task_id) {
|
|
|
|
|
String sql = "update t_yp_task set b_use=1,is_run=1 where task_id=?";
|
|
|
|
|
Db.update(sql, task_id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:根据身份证号计算班型
|
|
|
|
|
*
|
|
|
|
|
* @param sfzh
|
|
|
|
|
*/
|
|
|
|
|
public int evalBx(String sfzh) {
|
|
|
|
|
if (!IdcardUtil.isValidCard(sfzh)) return -1;//-1代表身份证不合法
|
|
|
|
|
//解析出出生日期
|
|
|
|
|
String birth = IdcardUtil.getBirthByIdCard(sfzh);
|
|
|
|
|
|
|
|
|
|
String sql = "select * from t_yp_bx where b_use=1";
|
|
|
|
|
List<Record> list = Db.find(sql);
|
|
|
|
|
|
|
|
|
|
//当前年份
|
|
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
|
|
int year = calendar.get(Calendar.YEAR);
|
|
|
|
|
int result = -2;
|
|
|
|
|
for (Record record : list) {
|
|
|
|
|
int bx_id = record.getInt("bx_id");
|
|
|
|
|
int start_year_num = record.getInt("start_year_num");
|
|
|
|
|
int end_year_num = record.getInt("end_year_num");
|
|
|
|
|
String start_month_day = record.getStr("start_month_day");
|
|
|
|
|
String end_month_day = record.getStr("end_month_day");
|
|
|
|
|
|
|
|
|
|
String st = year - start_year_num + start_month_day;
|
|
|
|
|
String ed = year - end_year_num + end_month_day;
|
|
|
|
|
if (birth.compareTo(st) >= 0 && birth.compareTo(ed) <= 0) {
|
|
|
|
|
result = bx_id;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;//如果result=-2表示不在指定的时间段内
|
|
|
|
|
}
|
|
|
|
|
}
|