parent
b32791b0c3
commit
b3b9ff80d4
@ -0,0 +1,124 @@
|
||||
package com.xxl.job.admin.controller;
|
||||
|
||||
import com.xxl.job.admin.core.model.XxlJobGroup;
|
||||
import com.xxl.job.admin.core.model.XxlJobUser;
|
||||
import com.xxl.job.admin.core.util.I18nUtil;
|
||||
import com.xxl.job.admin.dao.XxlJobGroupDao;
|
||||
import com.xxl.job.admin.dao.XxlJobUserDao;
|
||||
import com.xxl.job.core.biz.model.ReturnT;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.util.DigestUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author xuxueli 2019-05-04 16:39:50
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping("/user")
|
||||
public class UserController {
|
||||
|
||||
@Resource
|
||||
private XxlJobUserDao xxlJobUserDao;
|
||||
@Resource
|
||||
private XxlJobGroupDao xxlJobGroupDao;
|
||||
|
||||
@RequestMapping
|
||||
public String index(Model model) {
|
||||
|
||||
// 执行器列表
|
||||
List<XxlJobGroup> groupList = xxlJobGroupDao.findAll();
|
||||
model.addAttribute("groupList", groupList);
|
||||
|
||||
return "user/user.index";
|
||||
}
|
||||
|
||||
@RequestMapping("/pageList")
|
||||
@ResponseBody
|
||||
public Map<String, Object> pageList(@RequestParam(required = false, defaultValue = "0") int start,
|
||||
@RequestParam(required = false, defaultValue = "10") int length,
|
||||
String username) {
|
||||
|
||||
// page list
|
||||
List<XxlJobUser> list = xxlJobUserDao.pageList(start, length, username);
|
||||
int list_count = xxlJobUserDao.pageListCount(start, length, username);
|
||||
|
||||
// package result
|
||||
Map<String, Object> maps = new HashMap<String, Object>();
|
||||
maps.put("recordsTotal", list_count); // 总记录数
|
||||
maps.put("recordsFiltered", list_count); // 过滤后的总记录数
|
||||
maps.put("data", list); // 分页列表
|
||||
return maps;
|
||||
}
|
||||
|
||||
@RequestMapping("/add")
|
||||
@ResponseBody
|
||||
public ReturnT<String> add(XxlJobUser xxlJobUser) {
|
||||
|
||||
// valid username
|
||||
if (!StringUtils.hasText(xxlJobUser.getUsername())) {
|
||||
return new ReturnT<String>(ReturnT.FAIL_CODE, I18nUtil.getString("system_please_input")+I18nUtil.getString("user_username") );
|
||||
}
|
||||
xxlJobUser.setUsername(xxlJobUser.getUsername().trim());
|
||||
if (!(xxlJobUser.getUsername().length()>=4 && xxlJobUser.getUsername().length()<=20)) {
|
||||
return new ReturnT<String>(ReturnT.FAIL_CODE, I18nUtil.getString("system_lengh_limit")+"[4-20]" );
|
||||
}
|
||||
// valid password
|
||||
if (!StringUtils.hasText(xxlJobUser.getPassword())) {
|
||||
return new ReturnT<String>(ReturnT.FAIL_CODE, I18nUtil.getString("system_please_input")+I18nUtil.getString("user_password") );
|
||||
}
|
||||
xxlJobUser.setPassword(xxlJobUser.getPassword().trim());
|
||||
if (!(xxlJobUser.getPassword().length()>=4 && xxlJobUser.getPassword().length()<=20)) {
|
||||
return new ReturnT<String>(ReturnT.FAIL_CODE, I18nUtil.getString("system_lengh_limit")+"[4-20]" );
|
||||
}
|
||||
// md5 password
|
||||
xxlJobUser.setPassword(DigestUtils.md5DigestAsHex(xxlJobUser.getPassword().getBytes()));
|
||||
|
||||
// check repeat
|
||||
XxlJobUser existUser = xxlJobUserDao.loadByUserName(xxlJobUser.getUsername());
|
||||
if (existUser != null) {
|
||||
return new ReturnT<String>(ReturnT.FAIL_CODE, I18nUtil.getString("user_username_repeat") );
|
||||
}
|
||||
|
||||
// write
|
||||
xxlJobUserDao.save(xxlJobUser);
|
||||
return ReturnT.SUCCESS;
|
||||
}
|
||||
|
||||
@RequestMapping("/update")
|
||||
@ResponseBody
|
||||
public ReturnT<String> update(XxlJobUser xxlJobUser) {
|
||||
|
||||
// valid password
|
||||
if (StringUtils.hasText(xxlJobUser.getPassword())) {
|
||||
xxlJobUser.setPassword(xxlJobUser.getPassword().trim());
|
||||
if (!(xxlJobUser.getPassword().length()>=4 && xxlJobUser.getPassword().length()<=20)) {
|
||||
return new ReturnT<String>(ReturnT.FAIL_CODE, I18nUtil.getString("system_lengh_limit")+"[4-20]" );
|
||||
}
|
||||
// md5 password
|
||||
xxlJobUser.setPassword(DigestUtils.md5DigestAsHex(xxlJobUser.getPassword().getBytes()));
|
||||
} else {
|
||||
xxlJobUser.setPassword(null);
|
||||
}
|
||||
|
||||
// write
|
||||
xxlJobUserDao.update(xxlJobUser);
|
||||
return ReturnT.SUCCESS;
|
||||
}
|
||||
|
||||
@RequestMapping("/remove")
|
||||
@ResponseBody
|
||||
public ReturnT<String> remove(int id) {
|
||||
xxlJobUserDao.delete(id);
|
||||
return ReturnT.SUCCESS;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package com.xxl.job.admin.dao;
|
||||
|
||||
import com.xxl.job.admin.core.model.XxlJobUser;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author xuxueli 2019-05-04 16:44:59
|
||||
*/
|
||||
@Mapper
|
||||
public interface XxlJobUserDao {
|
||||
|
||||
public List<XxlJobUser> pageList(@Param("offset") int offset,
|
||||
@Param("pagesize") int pagesize,
|
||||
@Param("username") String username);
|
||||
public int pageListCount(@Param("offset") int offset,
|
||||
@Param("pagesize") int pagesize,
|
||||
@Param("username") String username);
|
||||
|
||||
public XxlJobUser loadByUserName(@Param("username") String username);
|
||||
|
||||
public int save(XxlJobUser xxlJobUser);
|
||||
|
||||
public int update(XxlJobUser xxlJobUser);
|
||||
|
||||
public int delete(@Param("id") int id);
|
||||
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.xxl.job.admin.dao.XxlJobUserDao">
|
||||
|
||||
<resultMap id="XxlJobUser" type="com.xxl.job.admin.core.model.XxlJobUser" >
|
||||
<result column="id" property="id" />
|
||||
<result column="username" property="username" />
|
||||
<result column="password" property="password" />
|
||||
<result column="role" property="role" />
|
||||
<result column="permission" property="permission" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
t.id,
|
||||
t.username,
|
||||
t.password,
|
||||
t.role,
|
||||
t.permission
|
||||
</sql>
|
||||
|
||||
<select id="pageList" parameterType="java.util.HashMap" resultMap="XxlJobUser">
|
||||
SELECT <include refid="Base_Column_List" />
|
||||
FROM XXL_JOB_QRTZ_USER AS t
|
||||
<trim prefix="WHERE" prefixOverrides="AND | OR" >
|
||||
<if test="username != null and username != ''">
|
||||
AND t.username like CONCAT(CONCAT('%', #{username}), '%')
|
||||
</if>
|
||||
</trim>
|
||||
ORDER BY username ASC
|
||||
LIMIT #{offset}, #{pagesize}
|
||||
</select>
|
||||
|
||||
<select id="pageListCount" parameterType="java.util.HashMap" resultType="int">
|
||||
SELECT count(1)
|
||||
FROM XXL_JOB_QRTZ_USER AS t
|
||||
<trim prefix="WHERE" prefixOverrides="AND | OR" >
|
||||
<if test="username != null and username != ''">
|
||||
AND t.username like CONCAT(CONCAT('%', #{username}), '%')
|
||||
</if>
|
||||
</trim>
|
||||
</select>
|
||||
|
||||
<select id="loadByUserName" parameterType="java.util.HashMap" resultMap="XxlJobUser">
|
||||
SELECT <include refid="Base_Column_List" />
|
||||
FROM XXL_JOB_QRTZ_USER AS t
|
||||
WHERE t.username = #{username}
|
||||
</select>
|
||||
|
||||
<insert id="save" parameterType="com.xxl.job.admin.core.model.XxlJobUser" useGeneratedKeys="true" keyProperty="id" >
|
||||
INSERT INTO XXL_JOB_QRTZ_USER (
|
||||
username,
|
||||
password,
|
||||
role,
|
||||
permission
|
||||
) VALUES (
|
||||
#{username},
|
||||
#{password},
|
||||
#{role},
|
||||
#{permission}
|
||||
);
|
||||
</insert>
|
||||
|
||||
<update id="update" parameterType="com.xxl.job.admin.core.model.XxlJobUser" >
|
||||
UPDATE XXL_JOB_QRTZ_USER
|
||||
SET
|
||||
<if test="password != null and password != ''">
|
||||
password = #{password},
|
||||
</if>
|
||||
role = #{role},
|
||||
permission = #{permission}
|
||||
WHERE id = #{id}
|
||||
</update>
|
||||
|
||||
<delete id="delete" parameterType="java.util.HashMap">
|
||||
DELETE
|
||||
FROM XXL_JOB_QRTZ_USER
|
||||
WHERE id = #{id}
|
||||
</delete>
|
||||
|
||||
</mapper>
|
@ -0,0 +1,179 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<#import "../common/common.macro.ftl" as netCommon>
|
||||
<@netCommon.commonStyle />
|
||||
<!-- DataTables -->
|
||||
<link rel="stylesheet" href="${request.contextPath}/static/adminlte/bower_components/datatables.net-bs/css/dataTables.bootstrap.min.css">
|
||||
<title>${I18n.admin_name}</title>
|
||||
</head>
|
||||
<body class="hold-transition skin-blue sidebar-mini <#if cookieMap?exists && cookieMap["xxljob_adminlte_settings"]?exists && "off" == cookieMap["xxljob_adminlte_settings"].value >sidebar-collapse</#if>">
|
||||
<div class="wrapper">
|
||||
<!-- header -->
|
||||
<@netCommon.commonHeader />
|
||||
<!-- left -->
|
||||
<@netCommon.commonLeft "user" />
|
||||
|
||||
<!-- Content Wrapper. Contains page content -->
|
||||
<div class="content-wrapper">
|
||||
<!-- Content Header (Page header) -->
|
||||
<section class="content-header">
|
||||
<h1>${I18n.user_manage}</h1>
|
||||
</section>
|
||||
|
||||
<!-- Main content -->
|
||||
<section class="content">
|
||||
|
||||
<div class="row">
|
||||
<div class="col-xs-3">
|
||||
<div class="input-group">
|
||||
<span class="input-group-addon">${I18n.user_username}</span>
|
||||
<input type="text" class="form-control" id="username" autocomplete="on" >
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xs-1">
|
||||
<button class="btn btn-block btn-info" id="searchBtn">${I18n.system_search}</button>
|
||||
</div>
|
||||
<div class="col-xs-2">
|
||||
<button class="btn btn-block btn-success add" type="button">${I18n.user_add}</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-xs-12">
|
||||
<div class="box">
|
||||
<div class="box-body" >
|
||||
<table id="user_list" class="table table-bordered table-striped" width="100%" >
|
||||
<thead>
|
||||
<tr>
|
||||
<th name="id" >ID</th>
|
||||
<th name="username" >${I18n.user_username}</th>
|
||||
<th name="password" >${I18n.user_password}</th>
|
||||
<th name="role" >${I18n.user_role}</th>
|
||||
<th name="permission" >${I18n.user_permission}</th>
|
||||
<th>${I18n.system_opt}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody></tbody>
|
||||
<tfoot></tfoot>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<!-- footer -->
|
||||
<@netCommon.commonFooter />
|
||||
</div>
|
||||
|
||||
<!-- 新增.模态框 -->
|
||||
<div class="modal fade" id="addModal" tabindex="-1" role="dialog" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h4 class="modal-title" >${I18n.user_add}</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form class="form-horizontal form" role="form" >
|
||||
<div class="form-group">
|
||||
<label for="lastname" class="col-sm-2 control-label">${I18n.user_username}<font color="red">*</font></label>
|
||||
<div class="col-sm-8"><input type="text" class="form-control" name="username" placeholder="${I18n.system_please_input}${I18n.user_username}" maxlength="50" ></div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="lastname" class="col-sm-2 control-label">${I18n.user_password}<font color="red">*</font></label>
|
||||
<div class="col-sm-8"><input type="text" class="form-control" name="password" placeholder="${I18n.system_please_input}${I18n.user_password}" maxlength="50" ></div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="lastname" class="col-sm-2 control-label">${I18n.user_role}<font color="red">*</font></label>
|
||||
<div class="col-sm-10">
|
||||
<input type="radio" name="role" value="0" checked />${I18n.user_role_normal}
|
||||
|
||||
<input type="radio" name="role" value="1" />${I18n.user_role_admin}
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="lastname" class="col-sm-2 control-label">${I18n.user_permission}<font color="black">*</font></label>
|
||||
<div class="col-sm-10">
|
||||
<#if groupList?exists && groupList?size gt 0>
|
||||
<#list groupList as item>
|
||||
<input type="checkbox" name="permission" value="${item.id}" />${item.title}(${item.appName})<br>
|
||||
</#list>
|
||||
</#if>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<hr>
|
||||
<div class="form-group">
|
||||
<div class="col-sm-offset-3 col-sm-6">
|
||||
<button type="submit" class="btn btn-primary" >${I18n.system_save}</button>
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal">${I18n.system_cancel}</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 更新.模态框 -->
|
||||
<div class="modal fade" id="updateModal" tabindex="-1" role="dialog" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h4 class="modal-title" >${I18n.user_update}</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form class="form-horizontal form" role="form" >
|
||||
<div class="form-group">
|
||||
<label for="lastname" class="col-sm-2 control-label">${I18n.user_username}<font color="red">*</font></label>
|
||||
<div class="col-sm-8"><input type="text" class="form-control" name="username" placeholder="${I18n.system_please_input}${I18n.user_username}" maxlength="50" readonly ></div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="lastname" class="col-sm-2 control-label">${I18n.user_password}<font color="red">*</font></label>
|
||||
<div class="col-sm-8"><input type="text" class="form-control" name="password" placeholder="${I18n.user_password_update_placeholder}" maxlength="50" ></div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="lastname" class="col-sm-2 control-label">${I18n.user_role}<font color="red">*</font></label>
|
||||
<div class="col-sm-10">
|
||||
<input type="radio" name="role" value="0" />${I18n.user_role_normal}
|
||||
|
||||
<input type="radio" name="role" value="1" />${I18n.user_role_admin}
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="lastname" class="col-sm-2 control-label">${I18n.user_permission}<font color="black">*</font></label>
|
||||
<div class="col-sm-10">
|
||||
<#if groupList?exists && groupList?size gt 0>
|
||||
<#list groupList as item>
|
||||
<input type="checkbox" name="permission" value="${item.id}" />${item.title}(${item.appName})<br>
|
||||
</#list>
|
||||
</#if>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<hr>
|
||||
<div class="form-group">
|
||||
<div class="col-sm-offset-3 col-sm-6">
|
||||
<button type="submit" class="btn btn-primary" >${I18n.system_save}</button>
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal">${I18n.system_cancel}</button>
|
||||
<input type="hidden" name="id" >
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<@netCommon.commonScript />
|
||||
<!-- DataTables -->
|
||||
<script src="${request.contextPath}/static/adminlte/bower_components/datatables.net/js/jquery.dataTables.min.js"></script>
|
||||
<script src="${request.contextPath}/static/adminlte/bower_components/datatables.net-bs/js/dataTables.bootstrap.min.js"></script>
|
||||
<script src="${request.contextPath}/static/plugins/jquery/jquery.validate.min.js"></script>
|
||||
<script src="${request.contextPath}/static/js/user.index.1.js"></script>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in new issue