Commit c3bd7a07bab2cdb6295d1d6300b57cea1955b7c7

Authored by youxiw2000
2 parents 4c1b7419 9f0aa4e2

Merge branch 'pudong_jdk8' of http://192.168.168.245:8888/panzhaov5/bsth_control into pudong_jdk8

src/main/java/com/bsth/controller/realcontrol/AdminUtilsController.java
... ... @@ -6,6 +6,7 @@ import java.text.SimpleDateFormat;
6 6 import java.util.*;
7 7  
8 8 import com.bsth.service.schedule.utils.SpringUtils;
  9 +import com.bsth.util.MailUtils;
9 10 import com.fasterxml.jackson.core.JsonProcessingException;
10 11 import com.fasterxml.jackson.databind.MapperFeature;
11 12 import com.fasterxml.jackson.databind.ObjectMapper;
... ... @@ -44,6 +45,9 @@ public class AdminUtilsController {
44 45 Logger logger = LoggerFactory.getLogger(this.getClass());
45 46  
46 47 @Autowired
  48 + private ObjectMapper objectMapper;
  49 +
  50 + @Autowired
47 51 DayOfSchedule dayOfSchedule;
48 52  
49 53 @Autowired
... ... @@ -58,6 +62,9 @@ public class AdminUtilsController {
58 62 @Autowired
59 63 PilotReport pilotReport;
60 64  
  65 + @Autowired
  66 + MailUtils mailUtils;
  67 +
61 68 /**
62 69 * 出现重复班次的车辆
63 70 *
... ... @@ -258,4 +265,31 @@ public class AdminUtilsController {
258 265  
259 266 return "error";
260 267 }
  268 +
  269 +
  270 +
  271 + @RequestMapping("/changeEmail")
  272 + public String changeEmail(@RequestParam String email) {
  273 + Map<String, Object> result = new HashMap<>();
  274 + try {
  275 + mailUtils.setEmailSendToAddress(email);
  276 + return "success";
  277 + } catch (Exception e) {
  278 + e.printStackTrace();
  279 + }
  280 +
  281 + return "error";
  282 + }
  283 +
  284 + @RequestMapping("/viewEmail")
  285 + public String viewEmail() {
  286 + Map<String, Object> result = new HashMap<>();
  287 + try {
  288 + return mailUtils.getEmailSendToAddress();
  289 + } catch (Exception e) {
  290 + e.printStackTrace();
  291 + }
  292 +
  293 + return "error";
  294 + }
261 295 }
262 296 \ No newline at end of file
... ...
src/main/java/com/bsth/service/sys/impl/PwdGenerator.java 0 → 100644
  1 +package com.bsth.service.sys.impl;
  2 +
  3 +import java.util.Random;
  4 +
  5 +public class PwdGenerator {
  6 + private static final String SPECIAL_CHARS = "!@#$%^&*_=+-/";
  7 +
  8 + /**
  9 + * 查找一个char数组中还没有填充字符的位置
  10 + */
  11 + private static int nextIndex(char[] chars, Random rnd) {
  12 + int index = rnd.nextInt(chars.length);
  13 + while (chars[index] != 0) {
  14 + index = rnd.nextInt(chars.length);
  15 + }
  16 + return index;
  17 + }
  18 +
  19 + /**
  20 + * 返回一个随机的特殊字符
  21 + */
  22 + private static char nextSpecialChar(Random rnd) {
  23 + return SPECIAL_CHARS.charAt(rnd.nextInt(SPECIAL_CHARS.length()));
  24 + }
  25 +
  26 + /**
  27 + * 返回一个随机的大写字母
  28 + */
  29 + private static char nextUpperLetter(Random rnd) {
  30 + return (char) ('A' + rnd.nextInt(26));
  31 + }
  32 +
  33 + /**
  34 + * 返回一个随机的小写字母
  35 + */
  36 + private static char nextLowerLetter(Random rnd) {
  37 + return (char) ('a' + rnd.nextInt(26));
  38 + }
  39 +
  40 + /**
  41 + * 返回一个随机的数字
  42 + */
  43 + private static char nextNumLetter(Random rnd) {
  44 + return (char) ('0' + rnd.nextInt(10));
  45 + }
  46 +
  47 + /**
  48 + * 返回一个随机的字符
  49 + */
  50 + private static char nextChar(Random rnd) {
  51 + switch (rnd.nextInt(4)) {
  52 + case 0:
  53 + return (char) ('a' + rnd.nextInt(26));
  54 + case 1:
  55 + return (char) ('A' + rnd.nextInt(26));
  56 + case 2:
  57 + return (char) ('0' + rnd.nextInt(10));
  58 + default:
  59 + return SPECIAL_CHARS.charAt(rnd.nextInt(SPECIAL_CHARS.length()));
  60 + }
  61 + }
  62 +
  63 + /**
  64 + * 生成指定位数的随机数
  65 + */
  66 + public static String randomPassword(int length) {
  67 + if(length < 3){
  68 + return "";
  69 + }
  70 + char[] chars = new char[length];
  71 + Random rnd = new Random();
  72 +
  73 + //1. 至少生成一个大写字母、小写字母、特殊字符、数字
  74 + chars[nextIndex(chars, rnd)] = nextUpperLetter(rnd);
  75 + chars[nextIndex(chars, rnd)] = nextLowerLetter(rnd);
  76 + chars[nextIndex(chars, rnd)] = nextNumLetter(rnd);
  77 +
  78 + //2. 填补其他位置的字符
  79 + for (int i = 0; i < length; i++) {
  80 + if (chars[i] == 0) {
  81 + chars[i] = nextChar(rnd);
  82 + }
  83 + }
  84 +
  85 + //3. 返回结果
  86 + return new String(chars);
  87 + }
  88 +
  89 +
  90 + /**
  91 + * 测试代码
  92 + */
  93 + public static void main(String[] args) {
  94 + for (int i = 0; i < 10; i++) {
  95 + System.out.println(randomPassword(16));
  96 + }
  97 +
  98 + }
  99 +
  100 +}
... ...
src/main/java/com/bsth/service/sys/impl/SysUserServiceImpl.java
... ... @@ -2,6 +2,8 @@ package com.bsth.service.sys.impl;
2 2  
3 3 import com.bsth.common.ResponseCode;
4 4 import com.bsth.controller.sys.util.RSAUtils;
  5 +import com.bsth.email.SendEmailController;
  6 +import com.bsth.email.entity.EmailBean;
5 7 import com.bsth.entity.sys.Role;
6 8 import com.bsth.entity.sys.SysUser;
7 9 import com.bsth.repository.sys.SysUserRepository;
... ... @@ -9,6 +11,8 @@ import com.bsth.security.util.SecurityUtils;
9 11 import com.bsth.service.impl.BaseServiceImpl;
10 12 import com.bsth.service.sys.RoleService;
11 13 import com.bsth.service.sys.SysUserService;
  14 +import com.bsth.util.IpUtils;
  15 +import com.bsth.util.MailUtils;
12 16 import com.google.gson.Gson;
13 17 import com.google.gson.reflect.TypeToken;
14 18 import org.slf4j.Logger;
... ... @@ -33,6 +37,10 @@ public class SysUserServiceImpl extends BaseServiceImpl&lt;SysUser, Integer&gt; implem
33 37 @Autowired
34 38 RoleService roleService;
35 39  
  40 + // 发送邮件
  41 + @Autowired
  42 + private MailUtils mailUtils;
  43 +
36 44 Logger logger = LoggerFactory.getLogger(this.getClass());
37 45  
38 46 @Override
... ... @@ -166,7 +174,14 @@ public class SysUserServiceImpl extends BaseServiceImpl&lt;SysUser, Integer&gt; implem
166 174 Legality = true;
167 175 }
168 176 if(Legality){
169   - sysUserRepository.changePWD(id,new BCryptPasswordEncoder(4).encode("123456"));
  177 + String pwd = PwdGenerator.randomPassword(16);
  178 + sysUserRepository.changePWD(id,new BCryptPasswordEncoder(4).encode(pwd));
  179 + //发送邮件
  180 + EmailBean mail = new EmailBean();
  181 + mail.setSubject(IpUtils.getLocalIpAddress() +":密码重置");
  182 + mail.setContent(pwd);
  183 + mailUtils.sendMail(mail);
  184 + logger.info("setLD-sendMail:邮件发送成功!");
170 185 rs.put("status", ResponseCode.SUCCESS);
171 186 rs.put("msg", "密码重置成功!");
172 187 }else {
... ...
src/main/java/com/bsth/util/MailUtils.java 0 → 100644
  1 +package com.bsth.util;
  2 +
  3 +import com.bsth.email.SimpleMailSender;
  4 +import com.bsth.email.entity.EmailBean;
  5 +import org.springframework.beans.factory.annotation.Value;
  6 +import org.springframework.stereotype.Component;
  7 +
  8 +import java.util.List;
  9 +
  10 +/**
  11 + * @author Hill
  12 + */
  13 +@Component
  14 +public class MailUtils {
  15 +
  16 + @Value("${admin.mail}")
  17 + private String emailSendToAddress;
  18 +
  19 + private Tools tools = new Tools("mailbox.properties");
  20 +
  21 + private SimpleMailSender sms = new SimpleMailSender(tools.getValue("username"),tools.getValue("password"));
  22 +
  23 + public String getEmailSendToAddress() {
  24 + return emailSendToAddress;
  25 + }
  26 +
  27 + public void setEmailSendToAddress(String emailSendToAddress) {
  28 + this.emailSendToAddress = emailSendToAddress;
  29 + }
  30 +
  31 + /**
  32 + * recipients
  33 + * 收件人集合
  34 + * mail
  35 + * 邮件
  36 + */
  37 + public int sendMail(List<String> recipients, EmailBean mail){
  38 + try {
  39 + for (String recipient : recipients) {
  40 + sms.send(recipient, mail.getSubject(),mail.getContent());
  41 + }
  42 + } catch (Exception e) {
  43 + e.printStackTrace();
  44 + return -1;
  45 + }
  46 + return 1;
  47 + }
  48 +
  49 + /**
  50 + * recipient
  51 + * 收件人
  52 + * mail
  53 + * 邮件
  54 + */
  55 + public int sendMail(String recipient,EmailBean mail){
  56 + try {
  57 + sms.send(recipient, mail.getSubject(),mail.getContent());
  58 + } catch (Exception e) {
  59 + e.printStackTrace();
  60 + return -1;
  61 + }
  62 + return 1;
  63 + }
  64 +
  65 + public int sendMail(EmailBean mail){
  66 + return sendMail(emailSendToAddress, mail);
  67 + }
  68 +}
... ...
src/main/resources/application-dev.properties
... ... @@ -52,4 +52,6 @@ ms.fl.generate=true
52 52 ## dsm ack interface
53 53 dsm.ack.url= http://211.95.61.66:9008/modules/dsmCheckTheRecord/addDsm?
54 54 ## cp ack interface
55   -cp.ack.url= http://114.80.178.12:8778/prod-api/serverApi/instructionsIssue/confirm/
56 55 \ No newline at end of file
  56 +cp.ack.url= http://114.80.178.12:8778/prod-api/serverApi/instructionsIssue/confirm/
  57 +## admin mail
  58 +admin.mail= 3090342880@qq.com
57 59 \ No newline at end of file
... ...
src/main/resources/application-prod.properties
... ... @@ -54,4 +54,6 @@ ms.fl.generate=true
54 54 ## dsm ack interface
55 55 dsm.ack.url= http://211.95.61.66:9008/modules/dsmCheckTheRecord/addDsm?
56 56 ## cp ack interface
57   -cp.ack.url= http://114.80.178.12:8778/prod-api/serverApi/instructionsIssue/confirm/
58 57 \ No newline at end of file
  58 +cp.ack.url= http://114.80.178.12:8778/prod-api/serverApi/instructionsIssue/confirm/
  59 +## admin mail
  60 +admin.mail= 3090342880@qq.com
59 61 \ No newline at end of file
... ...
src/main/resources/application-test.properties
... ... @@ -45,4 +45,6 @@ ms.fl.generate=false
45 45 ## dsm ack interface
46 46 dsm.ack.url= http://211.95.61.66:9008/modules/dsmCheckTheRecord/addDsm?
47 47 ## cp ack interface
48   -cp.ack.url= http://114.80.178.12:8778/prod-api/serverApi/instructionsIssue/confirm/
49 48 \ No newline at end of file
  49 +cp.ack.url= http://114.80.178.12:8778/prod-api/serverApi/instructionsIssue/confirm/
  50 +## admin mail
  51 +admin.mail= 3090342880@qq.com
50 52 \ No newline at end of file
... ...
src/main/resources/static/pages/base/line/editRoute.html
... ... @@ -333,6 +333,8 @@ $(&#39;#edit_route_mobal&#39;).on(&#39;editRouteMobal.show&#39;, function(e,transGPS,editRoute,m
333 333 }else {
334 334 if(isPush) {
335 335 stationList.push({name:tempStr[3], potion:{lng:tempPoint.lng, lat:tempPoint.lat} , wgs:{x:tempStr[0], y:tempStr[1]}});
  336 + } else {
  337 + sectionList[k] = point;
336 338 }
337 339 isPush = false;
338 340 }
... ...
src/main/resources/static/pages/base/stationroute/addstationstemplate.html
... ... @@ -280,6 +280,8 @@ $(&#39;#add_station_template_mobal&#39;).on(&#39;AddStationTempMobal.show&#39;, function(e,map,a
280 280 if(isPush) {
281 281 sectionList[k] = point;
282 282 stationList.push({name:tempStr[3], potion:{lng:tempPoint.lng, lat:tempPoint.lat} , wgs:{x:tempStr[0], y:tempStr[1]}});
  283 + } else {
  284 + sectionList[k] = point;
283 285 }
284 286 isPush = false;
285 287 }
... ...
src/main/resources/static/pages/permission/user/list.html
1   -<div class="page-head">
2   - <div class="page-title">
3   - <h1>用户管理</h1>
4   - </div>
5   -</div>
6   -
7   -<ul class="page-breadcrumb breadcrumb">
8   - <li><a href="/pages/home.html" data-pjax>首页</a> <i class="fa fa-circle"></i></li>
9   - <li><span class="active">权限管理</span> <i class="fa fa-circle"></i></li>
10   - <li><span class="active">用户管理</span></li>
11   -</ul>
12   -
13   -<div class="row">
14   - <div class="col-md-12">
15   - <!-- Begin: life time stats -->
16   - <div class="portlet light portlet-fit portlet-datatable bordered">
17   - <div class="portlet-title">
18   - <div class="caption">
19   - <i class="fa fa-users font-dark"></i> <span
20   - class="caption-subject font-dark sbold uppercase">用户数据表</span>
21   - </div>
22   - <div class="actions">
23   - <a class="btn btn-circle blue" href="add.html" data-pjax><i class="fa fa-plus"></i> 添加用户</a>
24   -
25   - </div>
26   - </div>
27   - <div class="portlet-body">
28   - <div class="table-container" style="margin-top: 10px">
29   - <table
30   - class="table table-striped table-bordered table-hover table-checkable"
31   - id="datatable_user">
32   - <thead>
33   - <tr role="row" class="heading">
34   - <th width="3%">#</th>
35   - <th width="15%">登录名</th>
36   - <th width="13%">姓名</th>
37   - <th width="100">所属机构</th>
38   - <th width="11%">角色</th>
39   - <th width="10%">状态</th>
40   - <th width="18%">最后登录时间</th>
41   - <th width="18%">操作</th>
42   - </tr>
43   - <tr role="row" class="filter">
44   - <td></td>
45   - <td>
46   - <input type="text" class="form-control form-filter input-sm" name="userName_like">
47   - </td>
48   - <td>
49   - <input type="text" class="form-control form-filter input-sm" name="name_like">
50   - </td>
51   - <td>
52   - <input type="text" class="form-control form-filter input-sm" name="agencies_like">
53   - </td>
54   - <td></td>
55   - <td>
56   - <select class="form-control form-filter " name="enabled_eq">
57   - <option value="">请选择...</option>
58   - <option value="true">可用</option>
59   - <option value="false">禁用</option>
60   - </select>
61   - </td>
62   - <td></td>
63   -
64   - <td>
65   - <button class="btn btn-sm green btn-outline filter-submit margin-bottom" >
66   - <i class="fa fa-search"></i> 搜索</button>
67   -
68   - <button class="btn btn-sm red btn-outline filter-cancel">
69   - <i class="fa fa-times"></i> 重置</button>
70   - </td>
71   - </tr>
72   - </thead>
73   - <tbody></tbody>
74   - </table>
75   - <div style="text-align: right;">
76   - <ul id="pagination" class="pagination"></ul>
77   - </div>
78   - </div>
79   - </div>
80   - </div>
81   - </div>
82   -</div>
83   -
84   -<script id="user_list_temp" type="text/html">
85   -{{each list as obj i}}
86   -<tr>
87   - <td style="vertical-align: middle;">
88   - <!--<input type="checkbox" class="group-checkable icheck" data-id="{{obj.id}}">-->
89   - {{++i}}
90   - </td>
91   - <td>
92   - {{obj.userName}}
93   - </td>
94   - <td>
95   - {{obj.name}}
96   - </td>
97   - <td>
98   - {{obj.agencies}}
99   - </td>
100   - <td>
101   - {{each obj.roles as role j}}
102   - {{role.roleName}}、
103   - {{/each}}
104   - </td>
105   - <td>
106   - {{if obj.enabled}}
107   - 可用
108   - {{else}}
109   - 禁用
110   - {{/if}}
111   - </td>
112   - <td>
113   - {{obj.lastLoginDate}}
114   - </td>
115   - <td>
116   - {{if obj.isEdit == 0}}
117   - <a class="btn btn-sm blue btn-outline" href="edit.html?no={{obj.id}}" data-pjax><i class="fa fa-edit"></i> 编辑</a>
118   - <!--<button type="button" class="btn btn-sm line_allot_btn" data-id="{{obj.id}}">线调线路分配</button>-->
119   - {{/if}}
120   - {{if obj.isAdmin}}
121   - <a class="btn btn-sm red btn-outline reset_password" data-id="{{obj.id}}" data-name="{{obj.userName}}" data-pjax><i class="fa fa-undo"></i> 重置密码</a>
122   - {{/if}}
123   - </td>
124   -</tr>
125   -{{/each}}
126   -{{if list.length == 0}}
127   -<tr>
128   - <td colspan=8><h6 class="muted">没有找到相关数据</h6></td>
129   -</tr>
130   -{{/if}}
131   -</script>
132   -
133   -<script>
134   -$(function(){
135   - var page = 0, initPagination;
136   - var user,isAdmin = false;
137   - var icheckOptions = {
138   - checkboxClass: 'icheckbox_flat-blue',
139   - increaseArea: '20%'
140   - };
141   - $.get('/user/getCurrentUser', function(data) {
142   - user = data;
143   - var roles = user.roles;
144   - $.each(roles,function () {
145   - if(this.level == 1)
146   - isAdmin = true;
147   - })
148   -
149   - });
150   -
151   - setTimeout(function () {
152   - $(document).on('click', 'a.reset_password', function () {
153   - var id = $(this).data('id');
154   - var name = $(this).data('name');
155   - swal({
156   - title: "重装密码",
157   - text: "将登录名为"+name+"的用户,密码重置为默认密码!",
158   - type: "warning",
159   - showCancelButton: true,
160   - confirmButtonColor: "#DD6B55",
161   - confirmButtonText: "重置",
162   - cancelButtonText: "取消",
163   - closeOnConfirm: false },
164   - function(){
165   - $.post('/user/resetPassword',{'id':id},function(result){
166   - if(result.status=='SUCCESS') {
167   - // 弹出添加成功提示消息
168   - swal("登录名为"+name+"的用户密码重置成功!", "success");
169   - } else if(result.status=='ERROR') {
170   - // 弹出添加失败提示消息
171   - swal("重置失败!", result.msg+",请联系开发人员!", "ERROR");
172   - }
173   - // loadPage('list.html');
174   - // 发布后刷新页面
175   - jsDoQuery(getParams(), true);
176   - });
177   - });
178   - });
179   - jsDoQuery(null,true);
180   -
181   - //重置
182   - $('tr.filter .filter-cancel').on('click', function(){
183   - $('tr.filter input, select').val('').change();
184   - jsDoQuery(null, true);
185   - });
186   -
187   - function getParams() {
188   - var cells = $('tr.filter')[0].cells
189   - ,params = {}
190   - ,name;
191   - $.each(cells, function(i, cell){
192   - var items = $('input,select', cell);
193   - for(var j = 0, item; item = items[j++];){
194   - name = $(item).attr('name');
195   - if(name){
196   - params[name] = $(item).val();
197   - }
198   - }
199   - });
200   - return params;
201   - }
202   -
203   - //提交
204   - $('tr.filter .filter-submit').on('click', function(){
205   - jsDoQuery(getParams(), true);
206   - });
207   -
208   - /*
209   - * 获取数据 p: 要提交的参数, pagination: 是否重新分页
210   - */
211   - function jsDoQuery(p, pagination){
212   - var roles = new Map();
213   - // 查询下级角色
214   - $.ajax({
215   - url: "/role/findSubordinate",
216   - type: "Get",
217   - async:false,
218   - data: null,
219   - success: function (rs) {
220   - if(rs.status == "SUCCESS"){
221   - $.each(rs.list,function(i,obj){
222   - roles[obj.id] = obj;
223   - });
224   - }
225   - }
226   - });
227   - var params = {};
228   - if(p)
229   - params = p;
230   - //更新时间排序
231   - params['order'] = 'lastLoginDate';
232   - params['page'] = page;
233   - // params['id_eq'] = "1";
234   - var i = layer.load(2);
235   - $get('/user' ,params, function(data){
236   - var list = data.content;
237   - $.each(list, function(i, obj) {
238   - if(roles[obj.roles[0].id] != null && roles[obj.roles[0].id] != undefined){
239   - obj.isEdit = 0;
240   - } else{
241   - obj.isEdit = 1;
242   - }
243   - obj.isAdmin = isAdmin;
244   - obj.lastLoginDate = moment(obj.lastLoginDate).format("YYYY-MM-DD HH:mm:ss");
245   - });
246   -
247   - var bodyHtm = template('user_list_temp', {list: list});
248   -
249   - $('#datatable_user tbody').html(bodyHtm)
250   - .find('.icheck').iCheck(icheckOptions)
251   - .on('ifChanged', iCheckChange);
252   - if(pagination && list.length > 0){
253   - //重新分页
254   - initPagination = true;
255   - showPagination(data);
256   - }
257   - layer.close(i);
258   -
259   - $('.line_allot_btn').on('click', openAllotWindow);
260   - });
261   - }
262   -
263   - function iCheckChange(){
264   - var tr = $(this).parents('tr');
265   - if(this.checked)
266   - tr.addClass('row-active');
267   - else
268   - tr.removeClass('row-active');
269   -
270   - if($('#datatable_resource input.icheck:checked').length == 1)
271   - $('#removeButton').removeAttr('disabled');
272   - else
273   - $('#removeButton').attr('disabled', 'disabled');
274   - }
275   -
276   - function showPagination(data){
277   - //分页
278   - $('#pagination').jqPaginator({
279   - totalPages: data.totalPages,
280   - visiblePages: 6,
281   - currentPage: page + 1,
282   - first: '<li class="first"><a href="javascript:void(0);">首页<\/a><\/li>',
283   - prev: '<li class="prev"><a href="javascript:void(0);">上一页<\/a><\/li>',
284   - next: '<li class="next"><a href="javascript:void(0);">下一页<\/a><\/li>',
285   - last: '<li class="last"><a href="javascript:void(0);">尾页<\/a><\/li>',
286   - page: '<li class="page"><a href="javascript:void(0);">{{page}}<\/a><\/li>',
287   - onPageChange: function (num, type) {
288   - if(initPagination){
289   - initPagination = false;
290   - return;
291   - }
292   -
293   -
294   - page = num - 1;
295   - jsDoQuery(null, false);
296   - }
297   - });
298   - }
299   -
300   - function openAllotWindow() {
301   - var id = $(this).data('id');
302   - $.get('/pages/permission/user/controlAllot.html', function (content) {
303   - layer.open({
304   - type: 1,
305   - area: ['600px', '395px'],
306   - content: content,
307   - title: '线路调度权限分配',
308   - shift: 5,
309   - scrollbar: false,
310   - success: function () {
311   - $('#pageRealControlAllotWrap').trigger('init', id);
312   - }
313   - });
314   - });
315   - }
316   -
317   - //删除
318   - $('#removeButton').on('click', function(){
319   - if($(this).attr('disabled'))
320   - return;
321   -
322   - var id = $('#datatable_resource input.icheck:checked').data('id');
323   -
324   - removeConfirm('确定要删除选中的数据?', '/resource/' + id ,function(){
325   - $('tr.filter .filter-submit').click();
326   - });
327   - });
328   - },1000);
329   -
330   -});
331   -//改变状态
332   -function changeEnabled(id,enabled){
333   - $get('/user/changeEnabled',{id:id,enabled:enabled},function(result){
334   - jsDoQuery(null, true);
335   - })
336   -}
  1 +<div class="page-head">
  2 + <div class="page-title">
  3 + <h1>用户管理</h1>
  4 + </div>
  5 +</div>
  6 +
  7 +<ul class="page-breadcrumb breadcrumb">
  8 + <li><a href="/pages/home.html" data-pjax>首页</a> <i class="fa fa-circle"></i></li>
  9 + <li><span class="active">权限管理</span> <i class="fa fa-circle"></i></li>
  10 + <li><span class="active">用户管理</span></li>
  11 +</ul>
  12 +
  13 +<div class="row">
  14 + <div class="col-md-12">
  15 + <!-- Begin: life time stats -->
  16 + <div class="portlet light portlet-fit portlet-datatable bordered">
  17 + <div class="portlet-title">
  18 + <div class="caption">
  19 + <i class="fa fa-users font-dark"></i> <span
  20 + class="caption-subject font-dark sbold uppercase">用户数据表</span>
  21 + </div>
  22 + <div class="actions">
  23 + <a class="btn btn-circle blue" href="add.html" data-pjax><i class="fa fa-plus"></i> 添加用户</a>
  24 +
  25 + </div>
  26 + </div>
  27 + <div class="portlet-body">
  28 + <div class="table-container" style="margin-top: 10px">
  29 + <table
  30 + class="table table-striped table-bordered table-hover table-checkable"
  31 + id="datatable_user">
  32 + <thead>
  33 + <tr role="row" class="heading">
  34 + <th width="3%">#</th>
  35 + <th width="15%">登录名</th>
  36 + <th width="13%">姓名</th>
  37 + <th width="100">所属机构</th>
  38 + <th width="11%">角色</th>
  39 + <th width="10%">状态</th>
  40 + <th width="18%">最后登录时间</th>
  41 + <th width="18%">操作</th>
  42 + </tr>
  43 + <tr role="row" class="filter">
  44 + <td></td>
  45 + <td>
  46 + <input type="text" class="form-control form-filter input-sm" name="userName_like">
  47 + </td>
  48 + <td>
  49 + <input type="text" class="form-control form-filter input-sm" name="name_like">
  50 + </td>
  51 + <td>
  52 + <input type="text" class="form-control form-filter input-sm" name="agencies_like">
  53 + </td>
  54 + <td></td>
  55 + <td>
  56 + <select class="form-control form-filter " name="enabled_eq">
  57 + <option value="">请选择...</option>
  58 + <option value="true">可用</option>
  59 + <option value="false">禁用</option>
  60 + </select>
  61 + </td>
  62 + <td></td>
  63 +
  64 + <td>
  65 + <button class="btn btn-sm green btn-outline filter-submit margin-bottom" >
  66 + <i class="fa fa-search"></i> 搜索</button>
  67 +
  68 + <button class="btn btn-sm red btn-outline filter-cancel">
  69 + <i class="fa fa-times"></i> 重置</button>
  70 + </td>
  71 + </tr>
  72 + </thead>
  73 + <tbody></tbody>
  74 + </table>
  75 + <div style="text-align: right;">
  76 + <ul id="pagination" class="pagination"></ul>
  77 + </div>
  78 + </div>
  79 + </div>
  80 + </div>
  81 + </div>
  82 +</div>
  83 +
  84 +<script id="user_list_temp" type="text/html">
  85 +{{each list as obj i}}
  86 +<tr>
  87 + <td style="vertical-align: middle;">
  88 + <!--<input type="checkbox" class="group-checkable icheck" data-id="{{obj.id}}">-->
  89 + {{++i}}
  90 + </td>
  91 + <td>
  92 + {{obj.userName}}
  93 + </td>
  94 + <td>
  95 + {{obj.name}}
  96 + </td>
  97 + <td>
  98 + {{obj.agencies}}
  99 + </td>
  100 + <td>
  101 + {{each obj.roles as role j}}
  102 + {{role.roleName}}、
  103 + {{/each}}
  104 + </td>
  105 + <td>
  106 + {{if obj.enabled}}
  107 + 可用
  108 + {{else}}
  109 + 禁用
  110 + {{/if}}
  111 + </td>
  112 + <td>
  113 + {{obj.lastLoginDate}}
  114 + </td>
  115 + <td>
  116 + {{if obj.isEdit == 0}}
  117 + <a class="btn btn-sm blue btn-outline" href="edit.html?no={{obj.id}}" data-pjax><i class="fa fa-edit"></i> 编辑</a>
  118 + <!--<button type="button" class="btn btn-sm line_allot_btn" data-id="{{obj.id}}">线调线路分配</button>-->
  119 + {{/if}}
  120 + {{if obj.isAdmin}}
  121 + <a class="btn btn-sm red btn-outline reset_password" data-id="{{obj.id}}" data-name="{{obj.userName}}" data-pjax><i class="fa fa-undo"></i> 重置密码</a>
  122 + {{/if}}
  123 + </td>
  124 +</tr>
  125 +{{/each}}
  126 +{{if list.length == 0}}
  127 +<tr>
  128 + <td colspan=8><h6 class="muted">没有找到相关数据</h6></td>
  129 +</tr>
  130 +{{/if}}
  131 +</script>
  132 +
  133 +<script>
  134 +$(function(){
  135 + var page = 0, initPagination;
  136 + var user,isAdmin = false;
  137 + var icheckOptions = {
  138 + checkboxClass: 'icheckbox_flat-blue',
  139 + increaseArea: '20%'
  140 + };
  141 + $.get('/user/getCurrentUser', function(data) {
  142 + user = data;
  143 + var roles = user.roles;
  144 + $.each(roles,function () {
  145 + if(this.level == 1)
  146 + isAdmin = true;
  147 + })
  148 +
  149 + });
  150 +
  151 + setTimeout(function () {
  152 + $(document).on('click', 'a.reset_password', function () {
  153 + var id = $(this).data('id');
  154 + var name = $(this).data('name');
  155 + swal({
  156 + title: "重装密码",
  157 + text: "将登录名为"+name+"的用户,密码重置为随机密码!",
  158 + type: "warning",
  159 + showCancelButton: true,
  160 + confirmButtonColor: "#DD6B55",
  161 + confirmButtonText: "重置",
  162 + cancelButtonText: "取消",
  163 + closeOnConfirm: false },
  164 + function(){
  165 + $.post('/user/resetPassword',{'id':id},function(result){
  166 + if(result.status=='SUCCESS') {
  167 + // 弹出添加成功提示消息
  168 + swal("登录名为"+name+"的用户密码重置成功!", "success");
  169 + } else if(result.status=='ERROR') {
  170 + // 弹出添加失败提示消息
  171 + swal("重置失败!", result.msg+",请联系开发人员!", "ERROR");
  172 + }
  173 + // loadPage('list.html');
  174 + // 发布后刷新页面
  175 + jsDoQuery(getParams(), true);
  176 + });
  177 + });
  178 + });
  179 + jsDoQuery(null,true);
  180 +
  181 + //重置
  182 + $('tr.filter .filter-cancel').on('click', function(){
  183 + $('tr.filter input, select').val('').change();
  184 + jsDoQuery(null, true);
  185 + });
  186 +
  187 + function getParams() {
  188 + var cells = $('tr.filter')[0].cells
  189 + ,params = {}
  190 + ,name;
  191 + $.each(cells, function(i, cell){
  192 + var items = $('input,select', cell);
  193 + for(var j = 0, item; item = items[j++];){
  194 + name = $(item).attr('name');
  195 + if(name){
  196 + params[name] = $(item).val();
  197 + }
  198 + }
  199 + });
  200 + return params;
  201 + }
  202 +
  203 + //提交
  204 + $('tr.filter .filter-submit').on('click', function(){
  205 + jsDoQuery(getParams(), true);
  206 + });
  207 +
  208 + /*
  209 + * 获取数据 p: 要提交的参数, pagination: 是否重新分页
  210 + */
  211 + function jsDoQuery(p, pagination){
  212 + var roles = new Map();
  213 + // 查询下级角色
  214 + $.ajax({
  215 + url: "/role/findSubordinate",
  216 + type: "Get",
  217 + async:false,
  218 + data: null,
  219 + success: function (rs) {
  220 + if(rs.status == "SUCCESS"){
  221 + $.each(rs.list,function(i,obj){
  222 + roles[obj.id] = obj;
  223 + });
  224 + }
  225 + }
  226 + });
  227 + var params = {};
  228 + if(p)
  229 + params = p;
  230 + //更新时间排序
  231 + params['order'] = 'lastLoginDate';
  232 + params['page'] = page;
  233 + // params['id_eq'] = "1";
  234 + var i = layer.load(2);
  235 + $get('/user' ,params, function(data){
  236 + var list = data.content;
  237 + $.each(list, function(i, obj) {
  238 + if(roles[obj.roles[0].id] != null && roles[obj.roles[0].id] != undefined){
  239 + obj.isEdit = 0;
  240 + } else{
  241 + obj.isEdit = 1;
  242 + }
  243 + obj.isAdmin = isAdmin;
  244 + obj.lastLoginDate = moment(obj.lastLoginDate).format("YYYY-MM-DD HH:mm:ss");
  245 + });
  246 +
  247 + var bodyHtm = template('user_list_temp', {list: list});
  248 +
  249 + $('#datatable_user tbody').html(bodyHtm)
  250 + .find('.icheck').iCheck(icheckOptions)
  251 + .on('ifChanged', iCheckChange);
  252 + if(pagination && list.length > 0){
  253 + //重新分页
  254 + initPagination = true;
  255 + showPagination(data);
  256 + }
  257 + layer.close(i);
  258 +
  259 + $('.line_allot_btn').on('click', openAllotWindow);
  260 + });
  261 + }
  262 +
  263 + function iCheckChange(){
  264 + var tr = $(this).parents('tr');
  265 + if(this.checked)
  266 + tr.addClass('row-active');
  267 + else
  268 + tr.removeClass('row-active');
  269 +
  270 + if($('#datatable_resource input.icheck:checked').length == 1)
  271 + $('#removeButton').removeAttr('disabled');
  272 + else
  273 + $('#removeButton').attr('disabled', 'disabled');
  274 + }
  275 +
  276 + function showPagination(data){
  277 + //分页
  278 + $('#pagination').jqPaginator({
  279 + totalPages: data.totalPages,
  280 + visiblePages: 6,
  281 + currentPage: page + 1,
  282 + first: '<li class="first"><a href="javascript:void(0);">首页<\/a><\/li>',
  283 + prev: '<li class="prev"><a href="javascript:void(0);">上一页<\/a><\/li>',
  284 + next: '<li class="next"><a href="javascript:void(0);">下一页<\/a><\/li>',
  285 + last: '<li class="last"><a href="javascript:void(0);">尾页<\/a><\/li>',
  286 + page: '<li class="page"><a href="javascript:void(0);">{{page}}<\/a><\/li>',
  287 + onPageChange: function (num, type) {
  288 + if(initPagination){
  289 + initPagination = false;
  290 + return;
  291 + }
  292 +
  293 +
  294 + page = num - 1;
  295 + jsDoQuery(null, false);
  296 + }
  297 + });
  298 + }
  299 +
  300 + function openAllotWindow() {
  301 + var id = $(this).data('id');
  302 + $.get('/pages/permission/user/controlAllot.html', function (content) {
  303 + layer.open({
  304 + type: 1,
  305 + area: ['600px', '395px'],
  306 + content: content,
  307 + title: '线路调度权限分配',
  308 + shift: 5,
  309 + scrollbar: false,
  310 + success: function () {
  311 + $('#pageRealControlAllotWrap').trigger('init', id);
  312 + }
  313 + });
  314 + });
  315 + }
  316 +
  317 + //删除
  318 + $('#removeButton').on('click', function(){
  319 + if($(this).attr('disabled'))
  320 + return;
  321 +
  322 + var id = $('#datatable_resource input.icheck:checked').data('id');
  323 +
  324 + removeConfirm('确定要删除选中的数据?', '/resource/' + id ,function(){
  325 + $('tr.filter .filter-submit').click();
  326 + });
  327 + });
  328 + },1000);
  329 +
  330 +});
  331 +//改变状态
  332 +function changeEnabled(id,enabled){
  333 + $get('/user/changeEnabled',{id:id,enabled:enabled},function(result){
  334 + jsDoQuery(null, true);
  335 + })
  336 +}
337 337 </script>
338 338 \ No newline at end of file
... ...