老项目,jdk1.7优化;pc端打卡统计,进行条件筛选过滤
下午写得,被带我某哥说了,arrayList和linkList大致区别,linkList双向链表增删快,arrayList数组,查找快,用迭代器时删除,导致每次下标索引重排,反而会影响性能:
String userName = request.getParameter("userName");
String status = request.getParameter("status");//状态
String state = request.getParameter("state");//洲别
String nation = request.getParameter("nation");//国别
if (nation != null && nation != "") {
state = null;
}
YWMobileLogin ywMobileLogin = (YWMobileLogin) request.getSession().getAttribute("userLoginZH");
// 获取其管理下所有教师和志愿者集合及人数 (指定地区)
List<YWMobileLogin> all = appUtil.getUser(ywMobileLogin);
if (userName != "" && userName!=null && !CollectionUtils.isEmpty(all)) {
Iterator<YWMobileLogin> iterator = all.iterator();
while (iterator.hasNext()) {
if (!iterator.next().getUserName().contains(userName)) {
iterator.remove();
}
}
}
if (state != "" && state != null && !CollectionUtils.isEmpty(all)) {
Iterator<YWMobileLogin> iterator = all.iterator();
while (iterator.hasNext()) {
if (!iterator.next().getZbName().equals(state)) {
iterator.remove();
}
}
}
if (nation != "" && nation != null && !CollectionUtils.isEmpty(all)) {
Iterator<YWMobileLogin> iterator = all.iterator();
while (iterator.hasNext()) {
if (!iterator.next().getNationName().equals(nation)) {
iterator.remove();
}
}
}
改正版1.0(先这样改吧,周一来了再给他看):
String userName = request.getParameter("userName");//姓氏
String status = request.getParameter("status");//状态
String state = request.getParameter("state");//洲别
String nation = request.getParameter("nation");//国别
Integer flag = 0;//表示洲别与国别对应关系
Boolean term = true;//表示姓氏存在
//当细分到国别时,洲别为空
if (!StringUtil.isNull(nation)) {
state = null;
}
if (!StringUtil.isNull(nation) && StringUtil.isNull(state)) {
flag = 1;
} else if (StringUtil.isNull(nation) && !StringUtil.isNull(state)) {
flag = 2;
}
YWMobileLogin ywMobileLogin = (YWMobileLogin) request.getSession().getAttribute("userLoginZH");
// 获取其管理下所有教师和志愿者集合及人数 (指定地区)
List<YWMobileLogin> list = appUtil.getUser(ywMobileLogin);
List<YWMobileLogin> all = new ArrayList<>();
if (!CollectionUtils.isEmpty(list)) {
List<YWMobileLogin> temporary = new ArrayList<>();
switch (flag) {
case 0: //洲别 和 国别为空
temporary.addAll(list);break;
case 1: // 洲别为空,国别不为空
for (YWMobileLogin mobileLogin : list) {
if (StringUtil.checkIsEqual(mobileLogin.getNationName(), nation)) {
temporary.add(mobileLogin);
}
}
break;
case 2:// 洲别不为空,国别为空
for (YWMobileLogin mobileLogin : list) {
if (StringUtil.checkIsEqual(mobileLogin.getZbName(), state)) {
temporary.add(mobileLogin);
}
}
break;
}
//姓氏判断
if (term && !CollectionUtils.isEmpty(temporary)) {
for (YWMobileLogin mobileLogin : temporary) {
if (StringUtil.checkIsEqual(mobileLogin.getUserName().substring(0,1),userName)) {
all.add(mobileLogin);
}
}
} else {all.addAll(temporary);}//姓氏不存在
}
业务接口全部代码
/**
* 获取打卡记录列表PC端整合
*/
@Override
public PageModel<PunchVo> getClockList(PageModel<PunchVo> page, HttpServletRequest request) throws Exception {
String userName = request.getParameter("userName");//姓氏
String status = request.getParameter("status");//状态
String state = request.getParameter("state");//洲别
String nation = request.getParameter("nation");//国别
Integer flag = 0;//表示洲别与国别对应关系
Boolean term = true;//表示姓氏存在
//当细分到国别时,洲别为空
if (!StringUtil.isNull(nation)) {
state = null;
}
if (!StringUtil.isNull(nation) && StringUtil.isNull(state)) {
flag = 1;
} else if (StringUtil.isNull(nation) && !StringUtil.isNull(state)) {
flag = 2;
}
YWMobileLogin ywMobileLogin = (YWMobileLogin) request.getSession().getAttribute("userLoginZH");
// 获取其管理下所有教师和志愿者集合及人数 (指定地区)
List<YWMobileLogin> list = appUtil.getUser(ywMobileLogin);
List<YWMobileLogin> all = new ArrayList<>();
if (!CollectionUtils.isEmpty(list)) {
List<YWMobileLogin> temporary = new ArrayList<>();
switch (flag) {
case 0: //洲别 和 国别为空
temporary.addAll(list);break;
case 1: // 洲别为空,国别不为空
for (YWMobileLogin mobileLogin : list) {
if (StringUtil.checkIsEqual(mobileLogin.getNationName(), nation)) {
temporary.add(mobileLogin);
}
}
break;
case 2:// 洲别不为空,国别为空
for (YWMobileLogin mobileLogin : list) {
if (StringUtil.checkIsEqual(mobileLogin.getZbName(), state)) {
temporary.add(mobileLogin);
}
}
break;
}
//姓氏判断
if (term && !CollectionUtils.isEmpty(temporary)) {
for (YWMobileLogin mobileLogin : temporary) {
if (StringUtil.checkIsEqual(mobileLogin.getUserName().substring(0,1),userName)) {
all.add(mobileLogin);
}
}
} else {all.addAll(temporary);}//姓氏不存在
}
List<PunchVo> punchVoList = new ArrayList<>();
//根据打卡人的id获取 打卡记录
if (!CollectionUtils.isEmpty(all)) {
StringBuffer platformIds = new StringBuffer();
Map<String, PunchVo> punchVoMap = new HashMap<>();
for (YWMobileLogin mobileLogin : all) {
if (!StringUtil.isNull(mobileLogin.getPlatUserId())) {
platformIds.append(",'" + mobileLogin.getPlatUserId() + "'");
punchVoMap.put(mobileLogin.getPlatUserId(), PunchVo.transform(mobileLogin));
}
}
String platformIdStr = platformIds.toString().replaceFirst(",", "");
String punchSql = " from Punch where TO_DAYS(date_punch) = TO_DAYS(now()) and userId " +
"in (" +platformIdStr + ") GROUP BY userId ORDER BY date_punch desc";
//防疫情况数据
List<Antiepidemic> antiepidemics = antiepidemicDao.find("from Antiepidemic where userId in (" + platformIdStr + ") order by createDate DESC ");
//当天打卡的数据
List<Punch> punchList = punchDao.find(punchSql);
HashMap<String, Antiepidemic> antiepidemicHashMap = new HashMap<>();
if (!CollectionUtils.isEmpty(antiepidemics)) {
for (Antiepidemic antiepidemic : antiepidemics) {
antiepidemicHashMap.put(antiepidemic.getUserId(), antiepidemic);
}
}
if (!CollectionUtils.isEmpty(punchList)) {
for (Punch punch : punchList) {
PunchVo punchVo = punchVoMap.get(punch.getUserId());
if (punchVo != null) {
BeanUtils.copyProperties(punch, punchVo);
punchVo.setFgXmgy(punch.getOfficerName());
punchVo.setId(punch.getUserId());
}
Antiepidemic antiepidemic = antiepidemicHashMap.get(punch.getUserId());
if (antiepidemic != null) {
punchVo.setIsVaccination(BigInteger.valueOf(antiepidemic.getIsVaccination()));
punchVo.setEvidenceNAT(antiepidemic.getEvidenceNAT());
punchVo.setDateNat(antiepidemic.getDateNAT());
}
}
}
//未打卡
if (status != null && status != "") {
if (StringUtil.checkIsEqual(status, "99") && !CollectionUtils.isEmpty(punchList)) {
for (Punch punch : punchList) {
punchVoMap.remove(punch.getUserId());
}
}
String[] array = {"1", "2", "3", "4", "5"};
//不舒服 到 正常
if (!CollectionUtils.isEmpty(punchList) && StringUtil.isContations(CollectionUtils.arrayToList(array), status)) {
Map<String, PunchVo> temporarya = new HashMap<>();
for (Punch punch : punchList) {
if (StringUtil.checkIsEqual(punch.getStatus().toString(), status)) {
temporarya.put(punch.getUserId(), punchVoMap.get(punch.getUserId()));
}
}
punchVoMap.clear();
punchVoMap.putAll(temporarya);
}
}
punchVoList.addAll(punchVoMap.values());
}
page.setDatas(punchVoList);
return getPageModel(page);
}
/*分页函数*/
private PageModel<PunchVo> getPageModel(PageModel<PunchVo> page) {
Integer pageNum = page.getCurrentPage();
Integer pageSize = page.getPageSize();
List<PunchVo> list = page.getDatas();
if (CollectionUtils.isEmpty(list)) {
return page;
}
int size = list.size();
if (pageSize > size) {
pageSize = size;
}
if (pageSize != 0) {
//求出最大页数,防止pageNum越界
int maxPageNum = size % pageSize == 0 ? size / pageSize : size / pageSize + 1;
if (pageNum > maxPageNum) {
pageNum = maxPageNum;
}
}
//当前页第一条数据的下表
int currentIndex = pageNum > 1 ? (pageNum - 1) * pageSize : 0;
List<PunchVo> pageList = new ArrayList<>();
//将当前页的数据放入到pageList中
for (int i = 0; i < pageSize && currentIndex + i < size; i++) {
pageList.add(list.get(currentIndex + i));
}
page.setCurrentPage(pageNum);
page.setPageSize(pageSize);
page.setTotalRows(list.size());
page.setDatas(pageList);
return page;
}