|
|
|
|
package com.dsideal.FengHuang.Yp.Model;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.date.DateTime;
|
|
|
|
|
import cn.hutool.core.util.IdcardUtil;
|
|
|
|
|
import com.jfinal.kit.Kv;
|
|
|
|
|
import com.jfinal.plugin.activerecord.Db;
|
|
|
|
|
import com.jfinal.plugin.activerecord.Page;
|
|
|
|
|
import com.jfinal.plugin.activerecord.Record;
|
|
|
|
|
import com.jfinal.plugin.activerecord.SqlPara;
|
|
|
|
|
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
|
public class YpModel {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:获取当前任务名称
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public List<Record> getCurrentTask() {
|
|
|
|
|
String sql = "select task_id,task_name,is_run from t_yp_task where b_use=1 and is_run=1";
|
|
|
|
|
List<Record> list = Db.find(sql);
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:获取指定任务的开启班型及人数限制
|
|
|
|
|
*/
|
|
|
|
|
public List<Record> getTaskLimit(int task_id) {
|
|
|
|
|
String sql = "select t1.*,t2.bx_name from t_yp_task_bx_limit as t1 inner join t_yp_bx as t2 on t1.bx_id=t2.bx_id where t1.task_id=?";
|
|
|
|
|
return Db.find(sql, task_id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:获取任务信息
|
|
|
|
|
*
|
|
|
|
|
* @param task_id
|
|
|
|
|
*/
|
|
|
|
|
public Record getTask(int task_id) {
|
|
|
|
|
Record record = Db.findById("t_yp_task", "task_id", task_id);
|
|
|
|
|
return record;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:增加任务
|
|
|
|
|
*/
|
|
|
|
|
public void addTask(String task_name, String bx_ids, String limits) {
|
|
|
|
|
Record record = new Record();
|
|
|
|
|
record.set("task_name", task_name);
|
|
|
|
|
record.set("create_time", DateTime.now());
|
|
|
|
|
record.set("b_use", 1);
|
|
|
|
|
record.set("is_run", 0);
|
|
|
|
|
Db.save("t_yp_task", "task_id", record);
|
|
|
|
|
String[] a = bx_ids.split(",");
|
|
|
|
|
String[] b = limits.split(",");
|
|
|
|
|
int task_id = record.getInt("task_id");
|
|
|
|
|
for (int i = 0; i < a.length; i++) {
|
|
|
|
|
Record r1 = new Record();
|
|
|
|
|
r1.set("task_id", task_id);
|
|
|
|
|
r1.set("bx_id", a[i]);
|
|
|
|
|
r1.set("limit", b[i]);
|
|
|
|
|
Db.save("t_yp_task_bx_limit", "task_id,bx_id", r1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:修改任务
|
|
|
|
|
*/
|
|
|
|
|
public void updateTask(int task_id, String task_name, String bx_ids, String limits) {
|
|
|
|
|
String sql = "update t_yp_task set task_name=? where task_id=?";
|
|
|
|
|
Db.update(sql, task_name, task_id);
|
|
|
|
|
|
|
|
|
|
String[] a = bx_ids.split(",");
|
|
|
|
|
String[] b = limits.split(",");
|
|
|
|
|
sql = "delete from t_yp_task_bx_limit where task_id=?";
|
|
|
|
|
Db.update(sql, task_id);
|
|
|
|
|
for (int i = 0; i < a.length; i++) {
|
|
|
|
|
Record r1 = new Record();
|
|
|
|
|
r1.set("task_id", task_id);
|
|
|
|
|
r1.set("bx_id", a[i]);
|
|
|
|
|
r1.set("limit", b[i]);
|
|
|
|
|
Db.save("t_yp_task_bx_limit", "task_id,bx_id", r1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:删除任务
|
|
|
|
|
*
|
|
|
|
|
* @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 is_run=0 where is_run=1";
|
|
|
|
|
Db.update(sql);
|
|
|
|
|
sql = "update t_yp_task set b_use=1,is_run=1 where task_id=?";
|
|
|
|
|
Db.update(sql, task_id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:停止任务
|
|
|
|
|
*
|
|
|
|
|
* @param task_id
|
|
|
|
|
*/
|
|
|
|
|
public void stopTask(int task_id) {
|
|
|
|
|
String sql = "update t_yp_task set is_run=0 where task_id=?";
|
|
|
|
|
Db.update(sql, task_id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:获取全局所有班型
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public List<Record> getAllBx() {
|
|
|
|
|
String sql = "select * from t_yp_bx where b_use=1";
|
|
|
|
|
List<Record> list = Db.find(sql);
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:根据身份证号计算班型
|
|
|
|
|
*
|
|
|
|
|
* @param sfzh
|
|
|
|
|
*/
|
|
|
|
|
public Kv evalBx(int task_id, String sfzh) {
|
|
|
|
|
Kv kv = Kv.create();
|
|
|
|
|
if (!IdcardUtil.isValidCard(sfzh)) {
|
|
|
|
|
kv.set("bx_id", -1);
|
|
|
|
|
kv.set("bx_name", "身份证不合法");
|
|
|
|
|
return kv;//-1代表身份证不合法
|
|
|
|
|
}
|
|
|
|
|
//解析出出生日期
|
|
|
|
|
String birth = IdcardUtil.getBirthByIdCard(sfzh);
|
|
|
|
|
List<Record> list = getAllBx();
|
|
|
|
|
|
|
|
|
|
//当前年份
|
|
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
|
|
int year = calendar.get(Calendar.YEAR);
|
|
|
|
|
int bx_id;
|
|
|
|
|
String bx_name;
|
|
|
|
|
for (Record record : list) {
|
|
|
|
|
bx_id = record.getInt("bx_id");
|
|
|
|
|
bx_name = record.getStr("bx_name");
|
|
|
|
|
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) {
|
|
|
|
|
//是不是满了呢?
|
|
|
|
|
int applyCount = applyCount(task_id, bx_id);
|
|
|
|
|
int limit_count = limitCount(task_id, bx_id);
|
|
|
|
|
if (limit_count == 0) break;
|
|
|
|
|
if (applyCount >= limit_count) {
|
|
|
|
|
kv.set("bx_id", -3);
|
|
|
|
|
kv.set("bx_name", "人数已满!");
|
|
|
|
|
kv.set("applyCount", applyCount);
|
|
|
|
|
kv.set("limit_count", limit_count);
|
|
|
|
|
return kv;
|
|
|
|
|
}
|
|
|
|
|
kv.set("bx_id", bx_id);
|
|
|
|
|
kv.set("applyCount", applyCount);
|
|
|
|
|
kv.set("limit_count", limit_count);
|
|
|
|
|
kv.set("bx_name", bx_name);
|
|
|
|
|
return kv;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
kv.set("bx_id", -2);
|
|
|
|
|
kv.set("bx_name", "出生日期不在指定的时间段内");
|
|
|
|
|
return kv;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:指定任务+指定班型的已申请人数
|
|
|
|
|
*
|
|
|
|
|
* @param task_id
|
|
|
|
|
* @param bx_id
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public int applyCount(int task_id, int bx_id) {
|
|
|
|
|
String sql = "select count(1) as count from t_yp_record where task_id=? and bx_id=?";
|
|
|
|
|
int count = Db.findFirst(sql, task_id, bx_id).getInt("count");
|
|
|
|
|
return count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:查看指定任务+指定班型的人数限制
|
|
|
|
|
*
|
|
|
|
|
* @param task_id
|
|
|
|
|
* @param bx_id
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public int limitCount(int task_id, int bx_id) {
|
|
|
|
|
String sql = "select * from t_yp_task_bx_limit where task_id=? and bx_id=?";
|
|
|
|
|
List<Record> list = Db.find(sql, task_id, bx_id);
|
|
|
|
|
if (list.size() == 0) return 0;
|
|
|
|
|
int limit_count = list.get(0).getInt("limit");
|
|
|
|
|
return limit_count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:保存申报结果
|
|
|
|
|
*
|
|
|
|
|
* @param task_id
|
|
|
|
|
* @param name
|
|
|
|
|
* @param xb
|
|
|
|
|
* @param bx_id
|
|
|
|
|
* @param address
|
|
|
|
|
* @param father_name
|
|
|
|
|
* @param mother_name
|
|
|
|
|
* @param sfzh
|
|
|
|
|
* @param tel
|
|
|
|
|
*/
|
|
|
|
|
public int save(int task_id, String name, String xb, int bx_id, String address, String father_name, String mother_name, String sfzh, String tel, String uuid) {
|
|
|
|
|
//1、检查身份证号是不是已存在
|
|
|
|
|
Record currentR = getCurrentTask().get(0);
|
|
|
|
|
String sql = "select count(1) as count from t_yp_record where sfzh=? and task_id=? and b_use=1";
|
|
|
|
|
int count = Db.findFirst(sql, sfzh, currentR.getInt("task_id")).getInt("count");
|
|
|
|
|
if (count > 0) return 2;
|
|
|
|
|
//2、是不是指定班型已招满
|
|
|
|
|
count = applyCount(task_id, bx_id);
|
|
|
|
|
//限制招多少人?
|
|
|
|
|
int limit_count = limitCount(task_id, bx_id);
|
|
|
|
|
if (count >= limit_count) return 3;
|
|
|
|
|
|
|
|
|
|
//3、保存
|
|
|
|
|
Record record = new Record();
|
|
|
|
|
record.set("task_id", task_id);
|
|
|
|
|
record.set("name", name);
|
|
|
|
|
record.set("xb", xb);
|
|
|
|
|
record.set("bx_id", bx_id);
|
|
|
|
|
record.set("address", address);
|
|
|
|
|
record.set("father_name", father_name);
|
|
|
|
|
record.set("mother_name", mother_name);
|
|
|
|
|
record.set("sfzh", sfzh);
|
|
|
|
|
record.set("tel", tel);
|
|
|
|
|
record.set("create_time", DateTime.now());
|
|
|
|
|
record.set("pic", "/upload/" + uuid + ".jpg");
|
|
|
|
|
Db.save("t_yp_record", "id", record);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:删除记录
|
|
|
|
|
* @param id
|
|
|
|
|
*/
|
|
|
|
|
public void delRecord(int id) {
|
|
|
|
|
String sql = "update t_yp_record set b_use=0 where id=?";
|
|
|
|
|
Db.update(sql, id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:查看指定任务的结果
|
|
|
|
|
*
|
|
|
|
|
* @param task_id
|
|
|
|
|
* @param bx_id
|
|
|
|
|
* @param page
|
|
|
|
|
* @param limit
|
|
|
|
|
*/
|
|
|
|
|
public Page<Record> getTaskInfo(int task_id, int bx_id, int page, int limit) {
|
|
|
|
|
Kv kv = Kv.by("task_id", task_id);
|
|
|
|
|
kv.set("bx_id", bx_id);
|
|
|
|
|
if (bx_id > 0) kv.set("bx_id", bx_id);
|
|
|
|
|
SqlPara sqlPara = Db.getSqlPara("yp.getTaskInfo", kv);
|
|
|
|
|
Page<Record> pageRecord = Db.paginate(page, limit, sqlPara);
|
|
|
|
|
return pageRecord;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:获取指定任务下的班型选择情况
|
|
|
|
|
*
|
|
|
|
|
* @param task_id
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public List<Record> getBx(int task_id) {
|
|
|
|
|
List<Record> all = getAllBx();
|
|
|
|
|
//本次任务的班型
|
|
|
|
|
String sql = "select * from t_yp_task_bx_limit where task_id=?";
|
|
|
|
|
List<Record> list = Db.find(sql, task_id);
|
|
|
|
|
Set<Integer> set = new HashSet<>();
|
|
|
|
|
Map<Integer, Integer> _map = new HashMap<>();
|
|
|
|
|
for (Record record : list) {
|
|
|
|
|
set.add(record.getInt("bx_id"));
|
|
|
|
|
_map.put(record.getInt("bx_id"), record.getInt("limit"));
|
|
|
|
|
}
|
|
|
|
|
for (Record record : all) {
|
|
|
|
|
if (set.contains(record.getInt("bx_id"))) {
|
|
|
|
|
record.set("selected", true);
|
|
|
|
|
record.set("limit", _map.get(record.getInt("bx_id")));
|
|
|
|
|
} else {
|
|
|
|
|
record.set("selected", false);
|
|
|
|
|
record.set("limit", 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return all;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:任务列表
|
|
|
|
|
*
|
|
|
|
|
* @param page
|
|
|
|
|
* @param limit
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public Page<Record> listTask(int page, int limit) {
|
|
|
|
|
SqlPara sqlPara = Db.getSqlPara("yp.listTask");
|
|
|
|
|
Page<Record> pageRecord = Db.paginate(page, limit, sqlPara);
|
|
|
|
|
return pageRecord;
|
|
|
|
|
}
|
|
|
|
|
}
|