diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/biz/JobUserController.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/biz/JobUserController.java index 51fd36c2..ed101d29 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/biz/JobUserController.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/biz/JobUserController.java @@ -6,12 +6,12 @@ import com.xxl.job.admin.mapper.XxlJobUserMapper; import com.xxl.job.admin.model.XxlJobGroup; import com.xxl.job.admin.model.XxlJobUser; import com.xxl.job.admin.util.I18nUtil; -import com.xxl.job.core.openapi.model.ReturnT; import com.xxl.sso.core.annotation.XxlSso; import com.xxl.sso.core.helper.XxlSsoHelper; import com.xxl.sso.core.model.LoginInfo; import com.xxl.tool.core.StringTool; import com.xxl.tool.encrypt.SHA256Tool; +import com.xxl.tool.response.PageModel; import com.xxl.tool.response.Response; import jakarta.annotation.Resource; import jakarta.servlet.http.HttpServletRequest; @@ -51,50 +51,50 @@ public class JobUserController { @RequestMapping("/pageList") @ResponseBody @XxlSso(role = Consts.ADMIN_ROLE) - public Map pageList(@RequestParam(value = "start", required = false, defaultValue = "0") int start, - @RequestParam(value = "length", required = false, defaultValue = "10") int length, - @RequestParam("username") String username, - @RequestParam("role") int role) { + public Response> pageList(@RequestParam(required = false, defaultValue = "0") int offset, + @RequestParam(required = false, defaultValue = "10") int pagesize, + @RequestParam String username, + @RequestParam int role) { // page list - List list = xxlJobUserMapper.pageList(start, length, username, role); - int list_count = xxlJobUserMapper.pageListCount(start, length, username, role); + List list = xxlJobUserMapper.pageList(offset, pagesize, username, role); + int list_count = xxlJobUserMapper.pageListCount(offset, pagesize, username, role); // filter - if (list!=null && list.size()>0) { + if (list!=null && !list.isEmpty()) { for (XxlJobUser item: list) { item.setPassword(null); } } // package result - Map maps = new HashMap(); - maps.put("recordsTotal", list_count); // 总记录数 - maps.put("recordsFiltered", list_count); // 过滤后的总记录数 - maps.put("data", list); // 分页列表 - return maps; + PageModel pageModel = new PageModel<>(); + pageModel.setPageData(list); + pageModel.setTotalCount(list_count); + + return Response.ofSuccess(pageModel); } @RequestMapping("/add") @ResponseBody @XxlSso(role = Consts.ADMIN_ROLE) - public ReturnT add(XxlJobUser xxlJobUser) { + public Response add(XxlJobUser xxlJobUser) { // valid username if (StringTool.isBlank(xxlJobUser.getUsername())) { - return ReturnT.ofFail(I18nUtil.getString("system_please_input")+I18nUtil.getString("user_username") ); + return Response.ofFail(I18nUtil.getString("system_please_input")+I18nUtil.getString("user_username") ); } xxlJobUser.setUsername(xxlJobUser.getUsername().trim()); if (!(xxlJobUser.getUsername().length()>=4 && xxlJobUser.getUsername().length()<=20)) { - return ReturnT.ofFail(I18nUtil.getString("system_lengh_limit")+"[4-20]" ); + return Response.ofFail(I18nUtil.getString("system_lengh_limit")+"[4-20]" ); } // valid password if (StringTool.isBlank(xxlJobUser.getPassword())) { - return ReturnT.ofFail(I18nUtil.getString("system_please_input")+I18nUtil.getString("user_password") ); + return Response.ofFail(I18nUtil.getString("system_please_input")+I18nUtil.getString("user_password") ); } xxlJobUser.setPassword(xxlJobUser.getPassword().trim()); if (!(xxlJobUser.getPassword().length()>=4 && xxlJobUser.getPassword().length()<=20)) { - return ReturnT.ofFail(I18nUtil.getString("system_lengh_limit")+"[4-20]" ); + return Response.ofFail(I18nUtil.getString("system_lengh_limit")+"[4-20]" ); } // md5 password String passwordHash = SHA256Tool.sha256(xxlJobUser.getPassword()); @@ -103,30 +103,30 @@ public class JobUserController { // check repeat XxlJobUser existUser = xxlJobUserMapper.loadByUserName(xxlJobUser.getUsername()); if (existUser != null) { - return ReturnT.ofFail( I18nUtil.getString("user_username_repeat") ); + return Response.ofFail( I18nUtil.getString("user_username_repeat") ); } // write xxlJobUserMapper.save(xxlJobUser); - return ReturnT.ofSuccess(); + return Response.ofSuccess(); } @RequestMapping("/update") @ResponseBody @XxlSso(role = Consts.ADMIN_ROLE) - public ReturnT update(HttpServletRequest request, XxlJobUser xxlJobUser) { + public Response update(HttpServletRequest request, XxlJobUser xxlJobUser) { // avoid opt login seft Response loginInfoResponse = XxlSsoHelper.loginCheckWithAttr(request); if (loginInfoResponse.getData().getUserName().equals(xxlJobUser.getUsername())) { - return ReturnT.ofFail(I18nUtil.getString("user_update_loginuser_limit")); + return Response.ofFail(I18nUtil.getString("user_update_loginuser_limit")); } // valid password if (StringTool.isNotBlank(xxlJobUser.getPassword())) { xxlJobUser.setPassword(xxlJobUser.getPassword().trim()); if (!(xxlJobUser.getPassword().length()>=4 && xxlJobUser.getPassword().length()<=20)) { - return ReturnT.ofFail(I18nUtil.getString("system_lengh_limit")+"[4-20]" ); + return Response.ofFail(I18nUtil.getString("system_lengh_limit")+"[4-20]" ); } // md5 password String passwordHash = SHA256Tool.sha256(xxlJobUser.getPassword()); @@ -137,40 +137,40 @@ public class JobUserController { // write xxlJobUserMapper.update(xxlJobUser); - return ReturnT.ofSuccess(); + return Response.ofSuccess(); } @RequestMapping("/remove") @ResponseBody @XxlSso(role = Consts.ADMIN_ROLE) - public ReturnT remove(HttpServletRequest request, @RequestParam("id") int id) { + public Response remove(HttpServletRequest request, @RequestParam("id") int id) { // avoid opt login seft Response loginInfoResponse = XxlSsoHelper.loginCheckWithAttr(request); if (Integer.parseInt(loginInfoResponse.getData().getUserId()) == id) { - return ReturnT.ofFail(I18nUtil.getString("user_update_loginuser_limit")); + return Response.ofFail(I18nUtil.getString("user_update_loginuser_limit")); } xxlJobUserMapper.delete(id); - return ReturnT.ofSuccess(); + return Response.ofSuccess(); } @RequestMapping("/updatePwd") @ResponseBody - public ReturnT updatePwd(HttpServletRequest request, + public Response updatePwd(HttpServletRequest request, @RequestParam("password") String password, @RequestParam("oldPassword") String oldPassword){ // valid if (oldPassword==null || oldPassword.trim().isEmpty()){ - return ReturnT.ofFail(I18nUtil.getString("system_please_input") + I18nUtil.getString("change_pwd_field_oldpwd")); + return Response.ofFail(I18nUtil.getString("system_please_input") + I18nUtil.getString("change_pwd_field_oldpwd")); } if (password==null || password.trim().isEmpty()){ - return ReturnT.ofFail(I18nUtil.getString("system_please_input") + I18nUtil.getString("change_pwd_field_oldpwd")); + return Response.ofFail(I18nUtil.getString("system_please_input") + I18nUtil.getString("change_pwd_field_oldpwd")); } password = password.trim(); if (!(password.length()>=4 && password.length()<=20)) { - return ReturnT.ofFail(I18nUtil.getString("system_lengh_limit")+"[4-20]" ); + return Response.ofFail(I18nUtil.getString("system_lengh_limit")+"[4-20]" ); } // md5 password @@ -181,14 +181,14 @@ public class JobUserController { Response loginInfoResponse = XxlSsoHelper.loginCheckWithAttr(request); XxlJobUser existUser = xxlJobUserMapper.loadByUserName(loginInfoResponse.getData().getUserName()); if (!oldPasswordHash.equals(existUser.getPassword())) { - return ReturnT.ofFail(I18nUtil.getString("change_pwd_field_oldpwd") + I18nUtil.getString("system_unvalid")); + return Response.ofFail(I18nUtil.getString("change_pwd_field_oldpwd") + I18nUtil.getString("system_unvalid")); } // write new existUser.setPassword(passwordHash); xxlJobUserMapper.update(existUser); - return ReturnT.ofSuccess(); + return Response.ofSuccess(); } } diff --git a/xxl-job-admin/src/main/resources/static/js/user.index.1.js b/xxl-job-admin/src/main/resources/static/js/user.index.1.js index 48d3f302..49851dd4 100644 --- a/xxl-job-admin/src/main/resources/static/js/user.index.1.js +++ b/xxl-job-admin/src/main/resources/static/js/user.index.1.js @@ -10,12 +10,20 @@ $(function() { type:"post", data : function ( d ) { var obj = {}; + obj.offset = d.start; + obj.pagesize = d.length; obj.username = $('#username').val(); obj.role = $('#role').val(); - obj.start = d.start; - obj.length = d.length; return obj; - } + }, + dataFilter: function (json ) { + var result = JSON.parse(json); + return JSON.stringify({ + "recordsTotal": result.data.totalCount, + "recordsFiltered": result.data.totalCount, + "data": result.data.pageData + }); + } }, "searching": false, "ordering": false,