// @RequiresPermissions("funds:tradingAccounts:edit") @RequestMapping(value = "save") public String save( TradingAccounts tradingAccounts, Model model, RedirectAttributes redirectAttributes) { String id = tradingAccounts.getId(); if (!beanValidator(model, tradingAccounts)) { return form(tradingAccounts, model, redirectAttributes); } /* 校验收据编号重复 */ boolean check = true; String receiptNo = ""; List<String> receiptNoList = new ArrayList<String>(); if (null != tradingAccounts.getReceiptList()) { for (Receipt receipt : tradingAccounts.getReceiptList()) { Receipt tmpReceipt = new Receipt(); tmpReceipt.setReceiptNo(receipt.getReceiptNo()); tmpReceipt.setDelFlag("0"); List<Receipt> list = receiptService.findList(tmpReceipt); if ((null != list && list.size() > 0)) { for (Receipt tReceipt : list) { if (receipt.getReceiptNo().equals(tReceipt.getReceiptNo()) && !tReceipt.getTradingAccounts().getId().equals(tradingAccounts.getId())) { receiptNo = receipt.getReceiptNo(); check = false; break; } } } if (receiptNoList.contains(receipt.getReceiptNo())) { receiptNo = receipt.getReceiptNo(); check = false; } if (!check) break; receiptNoList.add(receipt.getReceiptNo()); } } if (!check) { model.addAttribute("message", "收据编号:" + receiptNo + "重复或已存在."); model.addAttribute("messageType", ViewMessageTypeEnum.ERROR.getValue()); if (StringUtils.isEmpty(id)) { return form(tradingAccounts, model, redirectAttributes); } else { return "modules/funds/tradingAccountsForm"; } } tradingAccounts.setTradeStatus("0"); // 待审核 tradingAccountsService.save(tradingAccounts); addMessage(redirectAttributes, "保存账务交易成功"); if (StringUtils.isEmpty(id)) { return "redirect:" + Global.getAdminPath() + "/funds/paymentTrans/?repage"; } else { return "redirect:" + Global.getAdminPath() + "/funds/tradingAccounts/?repage"; } }
@RequiresPermissions("sys:dict:edit") @RequestMapping(value = "delete") public String delete(String id, RedirectAttributes redirectAttributes) { if (Global.isDemoMode()) { addMessage(redirectAttributes, "演示模式,不允许操作!"); return "redirect:" + Global.getAdminPath() + "/sys/dict/?repage"; } dictService.delete(id); addMessage(redirectAttributes, "删除字典成功"); return "redirect:" + Global.getAdminPath() + "/sys/dict/?repage"; }
@RequiresPermissions("sys:dict:edit") @RequestMapping(value = "save") // @Valid public String save( Dict dict, HttpServletRequest request, Model model, RedirectAttributes redirectAttributes) { if (Global.isDemoMode()) { addMessage(redirectAttributes, "演示模式,不允许操作!"); return "redirect:" + Global.getAdminPath() + "/sys/dict/?repage&type=" + dict.getType(); } if (!beanValidator(model, dict)) { return form(dict, model); } dictService.save(dict); addMessage(redirectAttributes, "保存字典'" + dict.getLabel() + "'成功"); return "redirect:" + Global.getAdminPath() + "/sys/dict/?repage&type=" + dict.getType(); }
/** * 获取工程路径 * * @return */ public static String getProjectPath() { // 如果配置了工程路径,则直接返回,否则自动获取。 String projectPath = Global.getConfig("projectPath"); if (StringUtils.isNotBlank(projectPath)) { return projectPath; } try { File file = new DefaultResourceLoader().getResource("").getFile(); if (file != null) { while (true) { File f = new File(file.getPath() + File.separator + "src" + File.separator + "main"); if (f == null || f.exists()) { break; } if (file.getParentFile() != null) { file = file.getParentFile(); } else { break; } } projectPath = file.toString(); } } catch (IOException e) { e.printStackTrace(); } return projectPath; }
@RequiresPermissions("renwu_run:renwuRun:edit") @RequestMapping(value = "save") public String save(RenwuRun renwuRun, Model model, RedirectAttributes redirectAttributes) { renwuRunService.save(renwuRun); addMessage(redirectAttributes, "保存任务成功"); return "redirect:" + Global.getAdminPath() + "/renwu_run/renwuRun/?repage"; }
@RequiresPermissions("zb:zbUser:edit") @RequestMapping(value = "delete") public String delete(ZbUser zbUser, RedirectAttributes redirectAttributes) { zbUserService.delete(zbUser); addMessage(redirectAttributes, "删除用户成功"); return "redirect:" + Global.getAdminPath() + "/zb/zbUser/?repage"; }
/** * 完成线上任务 * * @param onTaskId 线上任务ID * @param request * @param response POST不要使用@PathVariable * @return */ @RequestMapping(value = "onlinecomplete") public String onlineComplete( String onTaskId, HttpServletRequest request, HttpServletResponse response) { PgOnlineTask onlineTask = pgOnlineTaskService.get(onTaskId); // 线上任务 String onlineCheck = request.getParameter("answerChk"); // 用户选择的答案(ID) PgAnswer answer = pgAnswerService.get(onlineCheck); // 答案对象 if (answer != null && answer.getRightOrNot().equals("1")) { onlineTask.setRightOrNot("1"); // 答案是否正确(1:正确;0:错误) // 答题正确给予积分奖励 PgTaskList taskList = pgTaskListService.get(onlineTask.getTaskId()); PgOnlineQuestion onlineQuestion = pgOnlineQuestionService.get(taskList.getQuestionId()); Integer integral = onlineQuestion.getBaseIntegral(); // 构造方法PgIntegral(String integralDate,String integralType,Integer integral,User user) // 积分类型(integralType):0线上任务/1线下任务/2签到/3日记 PgIntegral pi = new PgIntegral(DateUtils.getDateTime(), "0", integral, UserUtils.getUser()); pi.setRemarks(onlineQuestion.getQuestion()); pgIntegralService.save(pi); } else { onlineTask.setRightOrNot("0"); // 答案是否正确(1:正确;0:错误) } onlineTask.setOnlineTaskStatus("1"); // 状态:1 表示已完成 onlineTask.setAnswerId(onlineCheck); // 用户选择的答案(ID) String answerType = ""; // 答题方式 // 未完成***********************************------------------------------------------- // 更新"是否正确" pgOnlineTaskService.save(onlineTask); // 更新会员在线任务 return "redirect:" + Global.getFrontPath() + "/task"; }
@RequiresPermissions("zb:zbUser:edit") @RequestMapping(value = "save") public String save(ZbUser zbUser, Model model, RedirectAttributes redirectAttributes) { if (!beanValidator(model, zbUser)) { return form(zbUser, model); } zbUserService.save(zbUser); addMessage(redirectAttributes, "保存用户成功"); return "redirect:" + Global.getAdminPath() + "/zb/zbUser/?repage"; }
@RequestMapping(value = "delete") public String delete(Long id, RedirectAttributes redirectAttributes) { if (Subject.isRoot(id)) { addMessage(redirectAttributes, "删除失败, 不允许删除顶级科目或编号为空"); } else { subjectService.deleteById(id); addMessage(redirectAttributes, "删除成功"); } return "redirect:" + Global.getAdminPath() + "/account/subject/"; }
@RequiresPermissions("wuyejiben:wuyeJiben:edit") @RequestMapping(value = "save") public String save(WuyeJiben wuyeJiben, Model model, RedirectAttributes redirectAttributes) { if (!beanValidator(model, wuyeJiben)) { return form(wuyeJiben, model); } wuyeJibenService.save(wuyeJiben); addMessage(redirectAttributes, "保存信息成功"); return "redirect:" + Global.getAdminPath() + "/wuyejiben/wuyeJiben/?repage"; }
@RequiresPermissions("wuyejiben:wuyeJiben:edit") @RequestMapping(value = "delete") public String delete(WuyeJiben wuyeJiben, RedirectAttributes redirectAttributes) { List<WuyeJiben> list = wuyeJibenService.loadSubById(wuyeJiben.getId()); if (list.size() == 0) { wuyeJibenService.delete(wuyeJiben); addMessage(redirectAttributes, "删除信息成功"); } else { addMessage(redirectAttributes, "请先删除公司下的小区!"); } return "redirect:" + Global.getAdminPath() + "/wuyejiben/wuyeJiben/?repage"; }
/** 授权查询回调函数, 进行鉴权但缓存中无用户的授权信息时调用 */ @Override protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) { Principal principal = (Principal) getAvailablePrincipal(principals); // 获取当前已登录的用户 if (!Global.TRUE.equals(Global.getConfig("user.multiAccountLogin"))) { Collection<Session> sessions = getSystemService() .getSessionDao() .getActiveSessions(true, principal, UserUtils.getSession()); if (sessions.size() > 0) { // 如果是登录进来的,则踢出已在线用户 if (UserUtils.getSubject().isAuthenticated()) { for (Session session : sessions) { getSystemService().getSessionDao().delete(session); } } // 记住我进来的,并且当前用户已登录,则退出当前用户提示信息。 else { UserUtils.getSubject().logout(); throw new AuthenticationException("msg:账号已在其它地方登录,请重新登录。"); } } } User user = getSystemService().getUserByLoginName(principal.getLoginName()); if (user != null) { SimpleAuthorizationInfo info = new SimpleAuthorizationInfo(); List<Menu> list = UserUtils.getMenuList(); for (Menu menu : list) { if (StringUtils.isNotBlank(menu.getPermission())) { // 添加基于Permission的权限信息 for (String permission : StringUtils.split(menu.getPermission(), ",")) { info.addStringPermission(permission); } } } // 添加用户权限 info.addStringPermission("user"); // 添加用户角色信息 for (Role role : user.getRoleList()) { info.addRole(role.getEnname()); } // 更新登录IP和时间 getSystemService().updateUserLoginInfo(user); // 记录登录日志 LogUtils.saveLog(Servlets.getRequest(), "系统登录"); return info; } else { return null; } }
/** * 完成线下任务 * * @param offTaskId * @param request * @param response * @param model * @return */ @RequestMapping(value = "offlinecomplete") public String offlinecomplete( String offTaskId, HttpServletRequest request, HttpServletResponse response, Model model) { model.addAttribute("site", site); String feel = request.getParameter("feel"); PgOfflineTask offlineTask = pgOfflineTaskService.get(offTaskId); offlineTask.setOfflineFeel(feel); offlineTask.setOfflineStatus("1"); // 状态:1 表示已完成 // 保存线下任务 pgOfflineTaskService.save(offlineTask); // 完成线下任务给予积分奖励 PgTaskList taskList = pgTaskListService.get(offlineTask.getTaskId()); PgOfflineQuestion offlineQuestion = pgOfflineQuestionService.get(taskList.getQuestionId()); Integer integral = offlineQuestion.getBaseIntegral(); // 构造方法PgIntegral(String integralDate,String integralType,Integer integral,User user) // 积分类型(integralType):0线上任务/1线下任务/2签到/3日记 PgIntegral pi = new PgIntegral(DateUtils.getDateTime(), "1", integral, UserUtils.getUser()); pi.setRemarks(offlineQuestion.getOfflineTask()); // 累计线下任务积分 pgIntegralService.save(pi); return "redirect:" + Global.getFrontPath() + "/task"; }
// @RequiresPermissions("funds:tradingAccounts:view") @RequestMapping(value = "form") public String form( TradingAccounts tradingAccounts, Model model, RedirectAttributes redirectAttributes) { String type = tradingAccounts.getTradeType(); if ("0".equals(type)) { // 承租合同直接处理,不跳转 tradingAccounts.setTradeStatus("1"); // 审核通过 tradingAccounts.setTradeDirection("0"); // 出账 tradingAccounts.setPayeeType("1"); // 交易人类型为“个人” String[] paymentTransIdArray = tradingAccounts.getTransIds().split(","); for (int i = 0; i < paymentTransIdArray.length; i++) { PaymentTrans paymentTrans = paymentTransService.get(paymentTransIdArray[i]); tradingAccounts.setId(null); tradingAccounts.setTradeAmount( paymentTrans.getTradeAmount() - paymentTrans.getTransAmount()); tradingAccounts.setTransIds(paymentTransIdArray[i]); tradingAccounts.setPayeeName( leaseContractService.get(paymentTrans.getTransId()).getRemittancerName()); if (tradingAccounts.getTradeAmount() > 0) { tradingAccountsService.save(tradingAccounts); } } addMessage(redirectAttributes, "保存账务交易成功"); return "redirect:" + Global.getAdminPath() + "/funds/paymentTrans/?repage"; } else { String[] paymentTransIdArray = tradingAccounts.getTransIds().split(","); double amount = 0; // 实际交易金额 String tradeType = ""; // 交易类型 String tradeObjectId = ""; // 交易对象ID Map<String, Receipt> paymentTypeMap = new HashMap<String, Receipt>(); for (int i = 0; i < paymentTransIdArray.length; i++) { PaymentTrans paymentTrans = paymentTransService.get(paymentTransIdArray[i]); if ("0".equals(paymentTrans.getTradeDirection())) { // 应出 amount -= paymentTrans.getLastAmount(); } else { // 应收 amount += paymentTrans.getLastAmount(); } tradeType = paymentTrans.getTradeType(); // 交易类型 tradeObjectId = paymentTrans.getTransId(); // 交易对象ID String paymentType = paymentTrans.getPaymentType(); // 款项类型 // 包含有出款的交易类型:0=承租合同,2=定金转违约,6=提前退租,7=正常退租,8=逾期退租,9=特殊退租 if ("0".equals(tradeType) || "2".equals(tradeType)) { // 0=承租合同,2=定金转违约不开收据 } else if ("6".equals(tradeType) || "7".equals(tradeType) || "8".equals(tradeType) || "9".equals(tradeType)) { } else { // 交易类型里的款项全是收款,不包含出款 if (!"0".equals(paymentTrans.getTradeDirection())) { // 应收款项 Receipt receipt = new Receipt(); if (paymentTypeMap.containsKey(paymentType)) { receipt = paymentTypeMap.get(paymentType); } receipt.setReceiptAmount( (null == receipt.getReceiptAmount() ? 0d : receipt.getReceiptAmount()) + paymentTrans.getLastAmount()); receipt.setPaymentType(paymentType); paymentTypeMap.put(paymentType, receipt); } } } List<Receipt> receiptList = new ArrayList<Receipt>(); /* 收据 */ if ("0".equals(tradeType) || "2".equals(tradeType)) { // 0=承租合同,2=定金转违约不开收据 } else if ("6".equals(tradeType) || "7".equals(tradeType) || "8".equals(tradeType) || "9".equals(tradeType)) { // 6=提前退租,7=正常退租,8=逾期退租,9=特殊退租 if (amount > 0) { // 总到账金额大于0 Receipt receipt = new Receipt(); receipt.setReceiptAmount( new BigDecimal(amount).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue()); receiptList.add(receipt); } } else { for (String key : paymentTypeMap.keySet()) { Receipt receipt = paymentTypeMap.get(key); receiptList.add(receipt); } } // 获取交易对象名称,设置交易对象名称、交易对象类型 if (StringUtils.isNotEmpty(tradeObjectId)) { DepositAgreement da = depositAgreementService.get(tradeObjectId); if (da != null) { // 定金协议承租人 List<Tenant> tenants = depositAgreementService.findTenant(da); // 定金协议的承租人列表 if (CollectionUtils.isNotEmpty(tenants)) { tradingAccounts.setPayeeName(tenants.get(0).getTenantName()); String tenantType = tenants.get(0).getTenantType(); // 租客类型 if ("0".equals(tenantType)) { // 个人租客 tradingAccounts.setPayeeType("1"); // 交易人类型为“个人” } if ("1".equals(tenantType)) { // 企业租客 tradingAccounts.setPayeeType("0"); // 交易人类型为“单位” } } } else { RentContract rc = rentContractService.get(tradeObjectId); if (rc != null) { // 出租合同承租人 List<Tenant> tenants = rentContractService.findTenant(rc); if (CollectionUtils.isNotEmpty(tenants)) { tradingAccounts.setPayeeName(tenants.get(0).getTenantName()); String tenantType = tenants.get(0).getTenantType(); // 租客类型 if ("0".equals(tenantType)) { // 个人租客 tradingAccounts.setPayeeType("1"); // 交易人类型为“个人” } if ("1".equals(tenantType)) { // 企业租客 tradingAccounts.setPayeeType("0"); // 交易人类型为“单位” } } } } } tradingAccounts.setTradeDirection(amount > 0 ? "1" : "0"); tradingAccounts.setTradeAmount( new BigDecimal(Math.abs(amount)).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue()); tradingAccounts.setTradeDirectionDesc( DictUtils.getDictLabel(tradingAccounts.getTradeDirection(), "trans_dirction", "")); tradingAccounts.setTradeType(tradeType); tradingAccounts.setTradeTypeDesc( DictUtils.getDictLabel(tradingAccounts.getTradeType(), "trans_type", "")); model.addAttribute("tradingAccounts", tradingAccounts); tradingAccounts.setReceiptList(receiptList); return "modules/funds/tradingAccountsForm"; } }
// @RequiresPermissions("funds:tradingAccounts:edit") @RequestMapping(value = "delete") public String delete(TradingAccounts tradingAccounts, RedirectAttributes redirectAttributes) { tradingAccountsService.delete(tradingAccounts); addMessage(redirectAttributes, "删除账务交易成功"); return "redirect:" + Global.getAdminPath() + "/funds/tradingAccounts/?repage"; }
/** * 分页类 * * @author ThinkGem * @version 2013-3-25 * @param <T> */ public class Page<T> { private int pageNo = 1; // 当前页码 private int pageSize = Integer.valueOf(Global.getConfig("page.pageSize")); // 页面大小,设置为“-1”表示不进行分页(分页无效) private long count; // 总记录数,设置为“-1”表示不查询总数 private int first; // 首页索引 private int last; // 尾页索引 private int prev; // 上一页索引 private int next; // 下一页索引 private boolean firstPage; // 是否是第一页 private boolean lastPage; // 是否是最后一页 private int length = 8; // 显示页面长度 private int slider = 1; // 前后显示页面长度 private List<T> list = new ArrayList<T>(); private String orderBy = ""; // 标准查询有效, 实例: updatedate desc, name asc private String funcName = "page"; // 设置点击页码调用的js函数名称,默认为page,在一页有多个分页对象时使用。 /** * 构造方法 * * @param request 传递 repage 参数,来记住页码 * @param response 用于设置 Cookie,记住页码 */ public Page(HttpServletRequest request, HttpServletResponse response) { this(request, response, -2); } /** * 构造方法 * * @param request 传递 repage 参数,来记住页码 * @param response 用于设置 Cookie,记住页码 * @param pageSize 分页大小,如果传递 -1 则为不分页,返回所有数据 */ public Page(HttpServletRequest request, HttpServletResponse response, int pageSize) { // 设置页码参数(传递repage参数,来记住页码) String no = request.getParameter("pageNo"); if (StringUtils.isNumeric(no)) { CookieUtils.setCookie(response, "pageNo", no); this.setPageNo(Integer.parseInt(no)); } else if (request.getParameter("repage") != null) { no = CookieUtils.getCookie(request, "pageNo"); if (StringUtils.isNumeric(no)) { this.setPageNo(Integer.parseInt(no)); } } // 设置页面大小参数(传递repage参数,来记住页码大小) String size = request.getParameter("pageSize"); if (StringUtils.isNumeric(size)) { CookieUtils.setCookie(response, "pageSize", size); this.setPageSize(Integer.parseInt(size)); } else if (request.getParameter("repage") != null) { no = CookieUtils.getCookie(request, "pageSize"); if (StringUtils.isNumeric(size)) { this.setPageSize(Integer.parseInt(size)); } } if (pageSize != -2) { this.pageSize = pageSize; } // 设置排序参数 String orderBy = request.getParameter("orderBy"); if (StringUtils.isNotBlank(orderBy)) { this.setOrderBy(orderBy); } } /** * 构造方法 * * @param pageNo 当前页码 * @param pageSize 分页大小 */ public Page(int pageNo, int pageSize) { this(pageNo, pageSize, 0); } /** * 构造方法 * * @param pageNo 当前页码 * @param pageSize 分页大小 * @param count 数据条数 */ public Page(int pageNo, int pageSize, long count) { this(pageNo, pageSize, count, new ArrayList<T>()); } /** * 构造方法 * * @param pageNo 当前页码 * @param pageSize 分页大小 * @param count 数据条数 * @param list 本页数据对象列表 */ public Page(int pageNo, int pageSize, long count, List<T> list) { this.setCount(count); this.setPageNo(pageNo); this.pageSize = pageSize; this.setList(list); } /** 初始化参数 */ public void initialize() { // 1 this.first = 1; this.last = (int) (count / (this.pageSize < 1 ? 20 : this.pageSize) + first - 1); if (this.count % this.pageSize != 0 || this.last == 0) { this.last++; } if (this.last < this.first) { this.last = this.first; } if (this.pageNo <= 1) { this.pageNo = this.first; this.firstPage = true; } if (this.pageNo >= this.last) { this.pageNo = this.last; this.lastPage = true; } if (this.pageNo < this.last - 1) { this.next = this.pageNo + 1; } else { this.next = this.last; } if (this.pageNo > 1) { this.prev = this.pageNo - 1; } else { this.prev = this.first; } // 2 if (this.pageNo < this.first) { // 如果当前页小于首页 this.pageNo = this.first; } if (this.pageNo > this.last) { // 如果当前页大于尾页 this.pageNo = this.last; } } /** 默认输出当前分页标签 <div class="page">${page}</div> */ @Override public String toString() { initialize(); StringBuilder sb = new StringBuilder(); if (pageNo == first) { // 如果是首页 sb.append("<li class=\"disabled\"><a href=\"javascript:\">« 上一页</a></li>\n"); } else { sb.append( "<li><a href=\"javascript:" + funcName + "(" + prev + "," + pageSize + ");\">« 上一页</a></li>\n"); } int begin = pageNo - (length / 2); if (begin < first) { begin = first; } int end = begin + length - 1; if (end >= last) { end = last; begin = end - length + 1; if (begin < first) { begin = first; } } if (begin > first) { int i = 0; for (i = first; i < first + slider && i < begin; i++) { sb.append( "<li><a href=\"javascript:" + funcName + "(" + i + "," + pageSize + ");\">" + (i + 1 - first) + "</a></li>\n"); } if (i < begin) { sb.append("<li class=\"disabled\"><a href=\"javascript:\">...</a></li>\n"); } } for (int i = begin; i <= end; i++) { if (i == pageNo) { sb.append( "<li class=\"active\"><a href=\"javascript:\">" + (i + 1 - first) + "</a></li>\n"); } else { sb.append( "<li><a href=\"javascript:" + funcName + "(" + i + "," + pageSize + ");\">" + (i + 1 - first) + "</a></li>\n"); } } if (last - end > slider) { sb.append("<li class=\"disabled\"><a href=\"javascript:\">...</a></li>\n"); end = last - slider; } for (int i = end + 1; i <= last; i++) { sb.append( "<li><a href=\"javascript:" + funcName + "(" + i + "," + pageSize + ");\">" + (i + 1 - first) + "</a></li>\n"); } if (pageNo == last) { sb.append("<li class=\"disabled\"><a href=\"javascript:\">下一页 »</a></li>\n"); } else { sb.append( "<li><a href=\"javascript:" + funcName + "(" + next + "," + pageSize + ");\">" + "下一页 »</a></li>\n"); } sb.append("<li class=\"disabled controls\"><a href=\"javascript:\">当前 "); sb.append( "<input type=\"text\" value=\"" + pageNo + "\" onkeypress=\"var e=window.event||this;var c=e.keyCode||e.which;if(c==13)"); sb.append(funcName + "(this.value," + pageSize + ");\" onclick=\"this.select();\"/> / "); sb.append( "<input type=\"text\" value=\"" + pageSize + "\" onkeypress=\"var e=window.event||this;var c=e.keyCode||e.which;if(c==13)"); sb.append(funcName + "(" + pageNo + ",this.value);\" onclick=\"this.select();\"/> 条,"); sb.append("共 " + count + " 条</a><li>\n"); sb.insert(0, "<ul>\n").append("</ul>\n"); sb.append("<div style=\"clear:both;\"></div>"); // sb.insert(0,"<div class=\"page\">\n").append("</div>\n"); return sb.toString(); } // public static void main(String[] args) { // Page<String> p = new Page<String>(3, 3); // System.out.println(p); // System.out.println("首页:"+p.getFirst()); // System.out.println("尾页:"+p.getLast()); // System.out.println("上页:"+p.getPrev()); // System.out.println("下页:"+p.getNext()); // } /** * 获取设置总数 * * @return */ public long getCount() { return count; } /** * 设置数据总数 * * @param count */ public void setCount(long count) { this.count = count; if (pageSize >= count) { pageNo = 1; } } /** * 获取当前页码 * * @return */ public int getPageNo() { return pageNo; } /** * 设置当前页码 * * @param pageNo */ public void setPageNo(int pageNo) { this.pageNo = pageNo; } /** * 获取页面大小 * * @return */ public int getPageSize() { return pageSize; } /** * 设置页面大小(最大500) * * @param pageSize */ public void setPageSize(int pageSize) { this.pageSize = pageSize <= 0 ? 10 : pageSize > 500 ? 500 : pageSize; } /** * 首页索引 * * @return */ public int getFirst() { return first; } /** * 尾页索引 * * @return */ public int getLast() { return last; } /** * 获取页面总数 * * @return getLast(); */ public int getTotalPage() { return getLast(); } /** * 是否为第一页 * * @return */ public boolean isFirstPage() { return firstPage; } /** * 是否为最后一页 * * @return */ public boolean isLastPage() { return lastPage; } /** * 上一页索引值 * * @return */ public int getPrev() { if (isFirstPage()) { return pageNo; } else { return pageNo - 1; } } /** * 下一页索引值 * * @return */ public int getNext() { if (isLastPage()) { return pageNo; } else { return pageNo + 1; } } /** * 获取本页数据对象列表 * * @return List<T> */ public List<T> getList() { return list; } /** * 设置本页数据对象列表 * * @param list */ public void setList(List<T> list) { this.list = list; } /** * 获取查询排序字符串 * * @return */ public String getOrderBy() { return orderBy; } /** 设置查询排序,标准查询有效, 实例: updatedate desc, name asc */ public void setOrderBy(String orderBy) { this.orderBy = orderBy; } /** * 获取点击页码调用的js函数名称 function * ${page.funcName}(pageNo){location="${ctx}/list-${category.id}${urlSuffix}?pageNo="+i;} * * @return */ public String getFuncName() { return funcName; } /** * 设置点击页码调用的js函数名称,默认为page,在一页有多个分页对象时使用。 * * @param funcName 默认为page */ public void setFuncName(String funcName) { this.funcName = funcName; } /** * 分页是否有效 * * @return this.pageSize==-1 */ public boolean isDisabled() { return this.pageSize == -1; } /** * 是否进行总数统计 * * @return this.count==-1 */ public boolean isNotCount() { return this.count == -1; } /** 获取 Hibernate FirstResult */ public int getFirstResult() { int firstResult = (getPageNo() - 1) * getPageSize(); if (firstResult >= getCount()) { firstResult = 0; } return firstResult; } /** 获取 Hibernate MaxResults */ public int getMaxResults() { return getPageSize(); } /** 获取 Spring data JPA 分页对象 */ public Pageable getSpringPage() { List<Order> orders = new ArrayList<Order>(); if (orderBy != null) { for (String order : StringUtils.split(orderBy, ",")) { String[] o = StringUtils.split(order, " "); if (o.length == 1) { orders.add(new Order(Direction.ASC, o[0])); } else if (o.length == 2) { if ("DESC".equals(o[1].toUpperCase())) { orders.add(new Order(Direction.DESC, o[0])); } else { orders.add(new Order(Direction.ASC, o[0])); } } } } return new PageRequest(this.pageNo - 1, this.pageSize, new Sort(orders)); } /** 设置 Spring data JPA 分页对象,转换为本系统分页对象 */ public void setSpringPage(org.springframework.data.domain.Page<T> page) { this.pageNo = page.getNumber(); this.pageSize = page.getSize(); this.count = page.getTotalElements(); this.list = page.getContent(); } }