/** * 显示类别(该类别的子类别也跟着显示) * * @param supvisorId 管理员id * @param typeId 隐藏类别的id * @param error * @return */ public static int showType(long supvisorId, long typeId, ErrorInfo error) { error.clear(); // String sql = "select status from t_content_news_types where id = ?"; // boolean status = false; // // try { // status = t_content_news_types.find(sql, typeId).first(); // } catch(Exception e) { // e.printStackTrace(); // error.msg = "查询类别状态失败"; // return -1; // } // // if(status) { // error.msg = "该类别已是显示状态"; // return -1; // } EntityManager em = JPA.em(); String mySql = "update t_content_news_types set status = ? where id = ?"; int rows = 0; try { rows = em.createQuery(mySql).setParameter(1, true).setParameter(2, typeId).executeUpdate(); } catch (Exception e) { e.printStackTrace(); Logger.info("显示类别,更新类别状态时:" + e.getMessage()); error.code = -1; error.msg = "更新类别状态失败"; return error.code; } if (rows == 0) { JPA.setRollbackOnly(); error.code = -1; error.msg = "数据未更新"; return error.code; } /* * 递归修改子类别的属性 */ String sql2 = "select id from t_content_news_types where parent_id = ?"; List<Long> ids = null; try { ids = t_content_news_types.find(sql2, typeId).fetch(); } catch (Exception e) { e.printStackTrace(); Logger.info("显示类别,查询子类别时:" + e.getMessage()); error.code = -2; error.msg = "更新类别状态失败"; return error.code; } if (ids != null && ids.size() != 0) { for (long id : ids) { showType(supvisorId, id, error); } } DealDetail.supervisorEvent(supvisorId, SupervisorEvent.SHOW_NEWSTYPE, "显示类别", error); if (error.code < 0) { JPA.setRollbackOnly(); return error.code; } error.code = 0; error.msg = "更新类别状态成功"; return 0; }