/** * 更新 * * @param ids * @param pIds * @param names * @param principalIds */ public void update(String ids, String pIds, String names, String principalIds) { Department dept = Department.dao.findById(ids); if (null != names && !names.isEmpty()) { // 更新模块名称 dept.set("names", names).update(); } else if (null != pIds && !pIds.isEmpty()) { // 更新上级模块 dept.set("parentdepartmentids", pIds).update(); } else if (null != principalIds && !principalIds.isEmpty()) { // 更新部门负责人 dept.set("principaluserids", principalIds).update(); } }
/** * 获取子节点数据 * * @param parentIds * @return */ public String childNodeData(String parentIds) { String sql = null; List<Department> list = null; if (null != parentIds) { sql = " select ids, names, isparent, images from pt_department where parentDepartmentIds = ? order by orderIds asc "; list = Department.dao.find(sql, parentIds); } else { sql = " select ids, names, isparent, images from pt_department where parentDepartmentIds is null order by orderIds asc "; list = Department.dao.find(sql); } StringBuilder sb = new StringBuilder(); sb.append("["); int size = list.size() - 1; for (Department dept : list) { sb.append(" { "); sb.append(" id : '").append(dept.getStr("ids")).append("', "); sb.append(" name : '").append(dept.getStr("names")).append("', "); sb.append(" isParent : true, "); sb.append(" font : {'font-weight':'bold'}, "); sb.append(" icon : '") .append("/jsFile/zTree/css/zTreeStyle/img/diy/") .append(dept.getStr("images")) .append("' "); sb.append(" }"); if (list.indexOf(dept) < size) { sb.append(", "); } } sb.append("]"); return sb.toString(); }
/** * 保存 * * @param pIds * @param names * @param orderIds * @return */ @Before(Tx.class) public String save(String pIds, String names, int orderIds) { Department pDept = Department.dao.findById(pIds); pDept.set("isparent", "true").update(); String images = ""; if (orderIds < 2 || orderIds > 9) { orderIds = 2; images = "2.png"; } else { images = orderIds + ".png"; } Department dept = new Department(); dept.set("isparent", "false"); dept.set("parentdepartmentids", pIds); dept.set("orderids", orderIds); dept.set("names", names); dept.set("images", images); dept.save(); return dept.getStr("ids"); }