|
@@ -0,0 +1,97 @@
|
|
|
|
|
+package space.apps.moudules.sys.services;
|
|
|
|
|
+
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
+
|
|
|
|
|
+import space.apps.moudules.basic.util.SortOrderUtil;
|
|
|
|
|
+import space.core.apps.util.GdbaQueryUtil;
|
|
|
|
|
+import space.core.common.utils.AESUtil;
|
|
|
|
|
+import space.core.common.utils.StringUtil;
|
|
|
|
|
+import space.core.db.bean.base.PageBean;
|
|
|
|
|
+import space.core.db.jdbc.GeneralDBAccess;
|
|
|
|
|
+import space.core.db.jdbc.SqlCommandImpl;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * Keeps the original authorization behavior while making the department tree
|
|
|
|
|
+ * filter the post list by the selected department and all of its descendants.
|
|
|
|
|
+ */
|
|
|
|
|
+public class PostAuthorizationService extends space.core.apps.sys.service.PostAuthorizationService {
|
|
|
|
|
+
|
|
|
|
|
+ private static final long serialVersionUID = 1L;
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public String postList() throws Exception {
|
|
|
|
|
+ PageBean pageBean = getAppsPageBean();
|
|
|
|
|
+ setRequestAttribute("departmentid", getParameter("departmentid"));
|
|
|
|
|
+ setRequestAttribute("postList", getPostList(getGdbaInstance(), pageBean));
|
|
|
|
|
+ return DEFAULT_FORWARD;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void getPostList_API() throws Exception {
|
|
|
|
|
+ PageBean pageBean = getAppsPageBean();
|
|
|
|
|
+ pageBean.setRowCountPerPage(999);
|
|
|
|
|
+ write(getResponseSuccessDataPackage(getPostList(getGdbaInstance(), pageBean)).toJson());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private List<Map<String, Object>> getPostList(GeneralDBAccess gdba, PageBean pageBean) throws Exception {
|
|
|
|
|
+ SqlCommandImpl sqlCmd = new SqlCommandImpl();
|
|
|
|
|
+ StringBuilder sqlBuilder = new StringBuilder();
|
|
|
|
|
+ sqlBuilder.append(" SELECT po.*, dept.name d_name, ut.name unit_name ");
|
|
|
|
|
+ sqlBuilder.append(" FROM post po ");
|
|
|
|
|
+ sqlBuilder.append(" LEFT JOIN department dept ON dept.departmentid = po.departmentid ");
|
|
|
|
|
+ sqlBuilder.append(" LEFT JOIN unit ut ON ut.unitid = dept.unitid ");
|
|
|
|
|
+ sqlBuilder.append(" WHERE po.dcode = 61 ");
|
|
|
|
|
+
|
|
|
|
|
+ appendDepartmentFilter(sqlBuilder, sqlCmd, getParameter("departmentid"));
|
|
|
|
|
+ GdbaQueryUtil.appendLikeSql(sqlBuilder, sqlCmd, "po.name", getParameter("name"));
|
|
|
|
|
+ sqlBuilder.append(" ORDER BY po.dcode ASC, ")
|
|
|
|
|
+ .append(SortOrderUtil.manualSort("dept", "sort_number", "create_time", "departmentid"))
|
|
|
|
|
+ .append(", ")
|
|
|
|
|
+ .append(SortOrderUtil.manualSort("po", "sort_number", "create_time", "postid"));
|
|
|
|
|
+ sqlCmd.setExecuteSql(sqlBuilder.toString());
|
|
|
|
|
+ return gdba.selectAsMapList(sqlCmd, pageBean);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void appendDepartmentFilter(StringBuilder sqlBuilder, SqlCommandImpl sqlCmd, String departmentIds) throws Exception {
|
|
|
|
|
+ List<String> ids = parseDepartmentIds(departmentIds);
|
|
|
|
|
+ if (ids.isEmpty()) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ sqlBuilder.append(" AND (");
|
|
|
|
|
+ for (int i = 0; i < ids.size(); i++) {
|
|
|
|
|
+ if (i > 0) {
|
|
|
|
|
+ sqlBuilder.append(" OR ");
|
|
|
|
|
+ }
|
|
|
|
|
+ String idParam = "departmentId" + i;
|
|
|
|
|
+ String pathParam = "departmentPath" + i;
|
|
|
|
|
+ sqlBuilder.append("dept.departmentid = :").append(idParam)
|
|
|
|
|
+ .append(" OR dept.parent_departmentid_list LIKE :").append(pathParam);
|
|
|
|
|
+ sqlCmd.setString(idParam, ids.get(i));
|
|
|
|
|
+ sqlCmd.setString(pathParam, "%\"" + ids.get(i) + "\"%");
|
|
|
|
|
+ }
|
|
|
|
|
+ sqlBuilder.append(") ");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private List<String> parseDepartmentIds(String departmentIds) throws Exception {
|
|
|
|
|
+ List<String> ids = new ArrayList<String>();
|
|
|
|
|
+ if (StringUtil.isNull(departmentIds)) {
|
|
|
|
|
+ return ids;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ for (String id : departmentIds.split(",")) {
|
|
|
|
|
+ String value = id == null ? "" : id.trim();
|
|
|
|
|
+ if (StringUtil.isNull(value)) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ String departmentId = value.matches("\\d+") ? value : AESUtil.decrypt(value);
|
|
|
|
|
+ if (StringUtil.notNull(departmentId) && departmentId.matches("\\d+")) {
|
|
|
|
|
+ ids.add(departmentId);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return ids;
|
|
|
|
|
+ }
|
|
|
|
|
+}
|