java 列表資料上下移動或置頂
阿新 • • 發佈:2019-01-24
/** * 排序 * @param id 公告序號 * @param type 排序型別 * 0:上移 * 1:下移 * 2:置頂 * @return */ @RequestMapping("sortThirdNotice") @ResponseBody public Result sortThirdNotice(Integer id, int type) { Result result = new Result(); try { resourseMgtService.sortThirdNotice(id, type); result.setStatus(Result.SUCCESS); result.setReason("排序成功"); } catch (Exception e) { log.error("error", e); result.setStatus(Result.FAILED); result.setReason("排序失敗"); } return result; }
@Override public void sortThirdNotice(Integer id, int type) { ThirdNoticeInfo notice = (ThirdNoticeInfo) getSession().createCriteria(ThirdNoticeInfo.class).add(Restrictions.ne("flag", -1)) .add(Restrictions.eq("id", id)).uniqueResult(); int sort = notice.getSort(); Criteria c = getSession().createCriteria(ThirdNoticeInfo.class).add(Restrictions.ne("flag", -1)); if (type == 0) { c.add(Restrictions.gt("sort", sort)); c.addOrder(Order.asc("sort")); } else if (type == 1) { c.add(Restrictions.lt("sort", sort)); c.addOrder(Order.desc("sort")); } else { c.add(Restrictions.gt("sort", sort)); c.addOrder(Order.desc("sort")); } c.setMaxResults(1); ThirdNoticeInfo sortNotice = (ThirdNoticeInfo) c.uniqueResult(); if (sortNotice != null) { if (type == 2) { this.updateThirdNoticeSort(notice.getId(), sortNotice.getSort()+1); } else { this.updateThirdNoticeSort(notice.getId(), sortNotice.getSort()); this.updateThirdNoticeSort(sortNotice.getId(), sort); } } } /** * @Title: updateThirdNoticeSort * @Description: (公告排序) * @param @param id * @param @param sort 設定檔案 * @return void 返回型別 * @throws */ private void updateThirdNoticeSort(Integer id, int sort) { getSession().createQuery("update ThirdNoticeInfo set sort=:s where id=:id ") .setParameter("s", sort).setParameter("id", id).executeUpdate(); }