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.

293 lines
9.6 KiB

2 years ago
package com.dsideal.FengHuang.Yp.Model;
2 years ago
import cn.hutool.core.date.DateTime;
2 years ago
import cn.hutool.core.util.IdcardUtil;
2 years ago
import com.jfinal.kit.Kv;
2 years ago
import com.jfinal.plugin.activerecord.Db;
2 years ago
import com.jfinal.plugin.activerecord.Page;
2 years ago
import com.jfinal.plugin.activerecord.Record;
2 years ago
import com.jfinal.plugin.activerecord.SqlPara;
2 years ago
import jnr.ffi.annotations.In;
2 years ago
2 years ago
import java.util.*;
2 years ago
public class YpModel {
/**
*
*
* @return
*/
2 years ago
public List<Record> getCurrentTaskInfo() {
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;
2 years ago
}
/**
*
*/
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);
}
2 years ago
public int getTaskApplyCount(int task_id, int bx_id) {
String 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);
return r1.getInt("count");
2 years ago
}
2 years ago
2 years ago
/**
*
* @param task_id
*/
public Record getTask(int task_id) {
Record record = Db.findById("t_yp_task", "task_id", task_id);
return record;
}
2 years ago
/**
*
*/
2 years ago
public void addTask(String task_name, String bx_id, String limits) {
2 years ago
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);
2 years ago
String[] a = bx_id.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);
}
2 years ago
}
/**
*
*/
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);
}
2 years ago
2 years ago
/**
*
*
* @param task_id
*/
2 years ago
public void startTask(int task_id) {
2 years ago
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=?";
2 years ago
Db.update(sql, task_id);
}
2 years ago
2 years ago
/**
*
*
* @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;
}
2 years ago
/**
*
*
* @param sfzh
*/
2 years ago
public Kv evalBx(int task_id, String sfzh) {
2 years ago
Kv kv = Kv.create();
if (!IdcardUtil.isValidCard(sfzh)) {
kv.set("bx_id", -1);
kv.set("bx_name", "身份证不合法");
return kv;//-1代表身份证不合法
}
2 years ago
//解析出出生日期
String birth = IdcardUtil.getBirthByIdCard(sfzh);
2 years ago
List<Record> list = getAllBx();
2 years ago
//当前年份
Calendar calendar = Calendar.getInstance();
int year = calendar.get(Calendar.YEAR);
2 years ago
int bx_id;
String bx_name;
2 years ago
for (Record record : list) {
2 years ago
bx_id = record.getInt("bx_id");
bx_name = record.getStr("bx_name");
2 years ago
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) {
2 years ago
//是不是满了呢?
int applyCount = getTaskApplyCount(task_id, bx_id);
int limit_count = limitCount(task_id, bx_id);
if (applyCount >= limit_count) {
kv.set("bx_id", -3);
kv.set("bx_name", "人数已满!");
2 years ago
kv.set("applyCount", applyCount);
kv.set("limit_count", limit_count);
2 years ago
return kv;
}
2 years ago
kv.set("bx_id", bx_id);
2 years ago
kv.set("applyCount", applyCount);
kv.set("limit_count", limit_count);
2 years ago
kv.set("bx_name", bx_name);
return kv;
2 years ago
}
}
2 years ago
kv.set("bx_id", -2);
kv.set("bx_name", "出生日期不在指定的时间段内");
2 years ago
return kv;
2 years ago
}
2 years ago
2 years ago
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;
}
public int limitCount(int task_id, int bx_id) {
String sql = "select * from t_yp_task_bx_limit where task_id=? and bx_id=?";
int limit_count = Db.findFirst(sql, task_id, bx_id).getInt("limit");
return limit_count;
}
2 years ago
/**
*
*
* @param task_id
* @param name
* @param xb
* @param bx_id
* @param address
* @param father_name
* @param mother_name
* @param sfzh
* @param tel
*/
2 years ago
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) {
2 years ago
//1、检查身份证号是不是已存在
String sql = "select count(1) as count from t_yp_record where sfzh=?";
int count = Db.findFirst(sql, sfzh).getInt("count");
if (count > 0) return 2;
//2、是不是指定班型已招满
2 years ago
count = applyCount(task_id, bx_id);
//限制招多少人?
int limit_count = limitCount(task_id, bx_id);
2 years ago
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);
2 years ago
record.set("create_time", DateTime.now());
2 years ago
record.set("pic", "/upload/" + uuid + ".jpg");
2 years ago
Db.save("t_yp_record", "id", record);
return 1;
}
2 years ago
2 years ago
/**
*
2 years ago
*
2 years ago
* @param task_id
* @param bx_id
* @param page
* @param limit
*/
2 years ago
public Page<Record> getTaskInfo(int task_id, int bx_id, int page, int limit) {
2 years ago
Kv kv = Kv.by("task_id", task_id);
2 years ago
kv.set("bx_id", bx_id);
2 years ago
if (bx_id > 0) kv.set("bx_id", bx_id);
2 years ago
SqlPara sqlPara = Db.getSqlPara("yp.getTaskInfo", kv);
Page<Record> pageRecord = Db.paginate(page, limit, sqlPara);
return pageRecord;
}
2 years ago
public void addBx(int task_id, int bx_id, int limit) {
delBx(task_id, bx_id);
Record record = new Record();
record.set("task_id", task_id);
record.set("bx_id", bx_id);
record.set("limit", limit);
Db.save("t_yp_task_bx_limit", "task_id,bx_id", record);
}
public void updateBx(int task_id, int bx_id, int limit) {
delBx(task_id, bx_id);
addBx(task_id, bx_id, limit);
}
public void delBx(int task_id, int bx_id) {
String sql = "delete from t_yp_task_bx_limit where task_id=? and bx_id=?";
Db.update(sql, task_id, bx_id);
}
2 years ago
/**
*
*
* @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<>();
2 years ago
Map<Integer,Integer> _map=new HashMap<>();
2 years ago
for (Record record : list) {
set.add(record.getInt("bx_id"));
2 years ago
_map.put(record.getInt("bx_id"),record.getInt("limit"));
2 years ago
}
for (Record record : all) {
if (set.contains(record.getInt("bx_id"))) {
record.set("selected", true);
2 years ago
record.set("limit",_map.get(record.getInt("bx_id")));
2 years ago
} else {
record.set("selected", false);
}
}
return all;
}
2 years ago
}