Helius
2021-06-16 5728be2af515b2200e782aa201ca5d4d67d9ea47
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
package com.ibeetl.admin.console.api;
 
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.ibeetl.admin.console.model.AppRoleModel;
import com.ibeetl.admin.console.model.CoreRoleModel;
import com.ibeetl.admin.console.model.CoreUserModel;
import com.ibeetl.admin.console.service.*;
import com.ibeetl.admin.console.web.query.*;
import com.ibeetl.admin.core.dao.CoreUserRoleDao;
import com.ibeetl.admin.core.entity.*;
import com.ibeetl.admin.core.rbac.UserLoginInfo;
import com.ibeetl.admin.core.rbac.tree.MenuItem;
import com.ibeetl.admin.core.rbac.tree.OrgItem;
import com.ibeetl.admin.core.service.CoreDictService;
import com.ibeetl.admin.core.service.CorePlatformService;
import com.ibeetl.admin.core.service.CoreRoleService;
import com.ibeetl.admin.core.service.CoreUserService;
import com.ibeetl.admin.core.util.*;
import com.ibeetl.admin.core.web.JsonResult;
import com.ibeetl.admin.core.web.dto.MenuNodeView;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.beetl.sql.core.engine.PageQuery;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.*;
import java.util.List;
 
/**
 * 用户管理
 */
@RestController
@Api(value = "登陆和用户管理的接口")
public class CuserApi {
 
    private static final String MODEL = "/admin/front";
    private final Logger log = LoggerFactory.getLogger(this.getClass());
 
    @Autowired
    CuserConsoleService service;
    @Autowired
    CoreUserService userService;
    @Autowired
    HttpRequestLocal httpRequestLocal;
    @Autowired
    CorePlatformService platformService;
    @Autowired
    RedisService redisService;
    @Autowired
    private DictConsoleService dictService;
    @Autowired
    XzxSysAddressLevelInfoService xzxSysAddressLevelInfoService;
    @Autowired
    UserConsoleService userConsoleService;
    @Autowired
    private OrgConsoleService orgConsoleService;
    @Autowired
    private RoleConsoleService roleConsoleService;
    @Autowired
    CoreDictService coreDictService;
    @Autowired
    FunctionConsoleService functionConsoleService;
    @Autowired
    CoreRoleService coreRoleService;
    @Autowired
    XzxCityPartnerService xzxCityPartnerService;
 
    /**
     * 登陆接口
     * @param request
     * @param response
     * @return
     */
    @PostMapping(MODEL+"/loginData.do")
    @ResponseBody
    @ApiOperation(value="用户登陆", notes="test: 仅0有正确返回")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "code", value = "用户ID", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "password", value = "密码", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "verify", value = "验证码", required = true, dataType = "String")
    })
    public JsonResult<Map<String,Object>> loginData(HttpServletRequest request, HttpServletResponse response, @RequestBody AppRoleModel model){
        //String ipAddr = request.getRequestURL().toString();
       String userType="1";
        Map<String,Object> resultMap = new HashMap<>();
        if(null!=redisService.get("xzx:user:verify:code")){
            System.out.println(redisService.get("xzx:user:verify:code").toString());
            if(!redisService.get("xzx:user:verify:code").toString().equalsIgnoreCase(model.getVerify())){
                /*if(ipAddr.indexOf("192.168.0.83") != -1){
                }else{*/
                if(!request.getSession().getAttribute("cap").toString().equalsIgnoreCase(model.getVerify())){
                    resultMap.put("code",-1);
                    resultMap.put("msg","验证码错误");
                    return JsonResult.failMessage("验证码错误");
                }
                //}
            }
        }else{
            if(!request.getSession().getAttribute("cap").toString().equalsIgnoreCase(model.getVerify())){
               /* if(ipAddr.indexOf("192.168.0.83") != -1){
                }else{*/
                    //redisService.set("xzx:user:verify:"+model.getCode(), request.getSession().getAttribute("cap").toString());
                    resultMap.put("code",-1);
                    resultMap.put("msg","验证码错误");
                    return JsonResult.failMessage("验证码错误");
                   //}
            }
        }
 
 
        String jsessionid = request.getSession().getId();
        Cookie cookie =new Cookie("JSESSIONID",jsessionid);
        cookie.setMaxAge(60*60*24*7);
        response.addCookie(cookie);
        String code = model.getCode();
        String password = model.getPassword();
        Map<String,Object> map = userService.loginApi(code, password,userType);
        Object obj = map.get("userLoginInfo");
        ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        UserLoginInfo info = objectMapper.convertValue(obj, UserLoginInfo.class);
 
        if (map.get("msg") != null) {
            return JsonResult.failMessage(map.get("msg").toString());
        }
        CoreUser user = info.getUser();
        redisService.remove("xzx:user:token:"+user.getId());
        //redisService.remove("xzx:user:verify:"+model.getCode());
        CoreOrg currentOrg = info.getOrgs().get(0);
        for (CoreOrg org : info.getOrgs()) {
            if (org.getId() == user.getOrgId()) {
                currentOrg = org;
                break;
            }
        }
        info.setCurrentOrg(currentOrg);
        // 记录登录信息到session
        this.platformService.setLoginUser(info.getUser(), info.getCurrentOrg(), info.getOrgs());
        String token = TokenUtils.createToken();
        redisService.set("xzx:user:loginToken:"+info.getUser().getId(), token);
        //Gson gson = new Gson();
        resultMap.put("userId",info.getUser().getId());
        resultMap.put("token",token);
        resultMap.put("userType",map.get("userType"));
        resultMap.put("jsessionid",jsessionid);
        //redisService.remove("xzx:user:verify:code");
        return JsonResult.success(resultMap);
    }
 
 
    @PostMapping("/logoutApi.do")
    @ResponseBody
    @ApiOperation(value="用户登出", notes="test: 仅0有正确返回")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "session", value = "需要把sessionId放入请求头", required = true, dataType = "String")
    })
    public JsonResult<String> logout(HttpServletRequest request) {
        HttpSession session = request.getSession();
        Enumeration eum = session.getAttributeNames();
        while(eum.hasMoreElements()) {
            String key = (String)eum.nextElement();
            session.removeAttribute(key);
        }
        return JsonResult.success("登出成功!");
 
    }
 
    /**
     * 菜单接口
     * @return
     */
    @PostMapping(MODEL+"/userMenu.do")
    @ApiOperation(value="用户获取菜单", notes="用户跨域获取权限菜单")
    @ResponseBody
    public JsonResult<Map<String, Object>> userMenu(){
        CoreUser user =platformService.getCurrentUser();
        //查询角色
        //CoreUserRole coreRole =coreRoleService.getRoleByUserId(user.getId(),user.getOrgId());
        //List<Long> dbs = functionConsoleService.getFunctionByRole(coreRole.getRoleId());
        //List<Long> dbs = functionConsoleService.getFunctionByRole(user.getRoleId());
        Map<String,Object> resultMap = new HashMap<>();
        List<MenuNodeView> allView= new ArrayList<>();
        List<MenuNodeView> view=new ArrayList<>();
        MenuItem allItem = platformService.getAllMenuItem();
        //判断是否是合伙人
        XzxCityPartner partner = xzxCityPartnerService.queryById(user.getId());
 
        if(null!=partner){
           /* String pUid = partner.getUserId();
            pUid =  pUid.substring(pUid.length()-6,pUid.length());
            XzxCityPartner pn = xzxCityPartnerService.queryEntityByUserIds(pUid);
            String userId = pn.getUserId().substring(pn.getUserId().length()-6,pn.getUserId().length());*/
            MenuItem menuItem = platformService.getPartnerMenuItem(partner.getId(), user.getOrgId());
            view = this.build(menuItem);
          }else{
              MenuItem menuItem = platformService.getMenuItem(user.getId(), user.getOrgId());
            view = this.build(menuItem);
          }
                  allView = this.build(allItem);
                  resultMap.put("user",user);
                  resultMap.put("menu",view);
                  resultMap.put("allView",allView);
        return JsonResult.success(resultMap);
    }
 
    private List<MenuNodeView> buildExitFunction(MenuItem node,List<Long> dbs) {
        List<MenuItem> list = node.getChildren();
        if (list.size() == 0) {
            return Collections.EMPTY_LIST;
        }
 
        List<MenuNodeView> views = new ArrayList<MenuNodeView>(list.size());
        for (MenuItem item : list) {
                    boolean bool = false;
            if(!item.getParent().getName().equals("主菜单")){
                for (Long menuId:dbs) {
                    if(menuId.equals(item.getId())){
                        bool=true;
                    }
                }
                if(bool){
                    MenuNodeView view = new MenuNodeView();
                    view.setCode(item.getData().getCode());
                    view.setName(item.getData().getName());
                    view.setIcon(item.getData().getIcon());
                    view.setId(item.getData().getId());
                    view.setCreateTime(item.getCreateTime());
 
                    view.setPath((String) item.getData().get("accessUrl"));
                    List<MenuNodeView> children = this.build(item);
                    view.setChildren(children);
                    views.add(view);
                }
            }else{
                MenuNodeView view = new MenuNodeView();
                view.setCode(item.getData().getCode());
                view.setName(item.getData().getName());
                view.setIcon(item.getData().getIcon());
                view.setId(item.getData().getId());
                view.setCreateTime(item.getCreateTime());
 
                view.setPath((String) item.getData().get("accessUrl"));
                List<MenuNodeView> children = this.buildExitFunction(item,dbs);
                view.setChildren(children);
                views.add(view);
            }
 
         }
 
        return views;
    }
 
    private List<MenuNodeView> build(MenuItem node) {
        List<MenuItem> list = node.getChildren();
        if (list.size() == 0) {
            return Collections.EMPTY_LIST;
        }
 
        List<MenuNodeView> views = new ArrayList<MenuNodeView>(list.size());
 
        for (MenuItem item : list) {
            MenuNodeView view = new MenuNodeView();
            view.setCode(item.getData().getCode());
            view.setName(item.getData().getName());
            view.setIcon(item.getData().getIcon());
            view.setId(item.getData().getId());
            view.setCreateTime(item.getCreateTime());
            view.setPath((String) item.getData().get("accessUrl"));
            List<MenuNodeView> children = this.build(item);
            view.setChildren(children);
            views.add(view);
        }
        return views;
    }
 
    /**
     * 用户管理列表接口
     * @param condtion
     * @return
     */
    @PostMapping(MODEL + "/userList.do")
    @ResponseBody
    @ApiOperation(value="用户管理列表接口", notes="test: 仅0有正确返回")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "code", value = "用户名", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "name", value = "姓名", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "orgId", value = "部门", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "state", value = "状态", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "jobType0", value = "职务", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "jobType1", value = "职务明细", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "startTime", value = "创建日期开始时间", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "endTime", value = "创建日期结束时间", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "limit", value = "每页数据个数", required = true, dataType = "int"),
            @ApiImplicitParam(paramType="query", name = "page", value = "页码", required = true, dataType = "int")
    })
    public JsonResult<PageQuery<CoreUserModel>> userList(@RequestBody CoreUserModel query) {
        //userConsoleService.queryByCondtion(query);
        List<CoreUserModel> list = userConsoleService.queryByCondtion(query);
        for (CoreUserModel model:list) {
            //查询角色Id
            CoreUserRole coreRole =coreRoleService.getRoleByUserId(model.getId(),model.getOrgId());
            if(null!=coreRole){
                model.setRoleId(coreRole.getRoleId());
                model.setOrgName(orgConsoleService.queryById(model.getOrgId()).getName());
                model.setJobType0Text(coreDictService.findNameByType(model.getJobType0()));
                model.setJobType1Text(coreDictService.findNameByType(model.getJobType1()));
                model.setStateText(coreDictService.findNameByType(model.getState()));
            }
 
        }
        PageQuery<CoreUserModel> result = new PageQuery();
        int count = userConsoleService.queryByCondtionCount(query);
        result.setTotalRow(count);
        /*result.setPageSize(page.getPageSize());
        result.setTotalRow(count);*/
        result.setList(list);
        return JsonResult.success(result);
    }
 
    /**
     * 用户管理删除操作
     * @param user
     * @return
     */
    @PostMapping(MODEL + "/userDelete.do")
    @ResponseBody
    @ApiOperation(value="用户管理(删除))", notes="test: 仅0有正确返回")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "id", value = "用户Id", required = true, dataType = "Long")
    })
    public JsonResult userDelete(@RequestBody CoreUser user) {
        List<Long> dels = new ArrayList<>();
        dels.add(user.getId());
        userConsoleService.batchDelSysUser(dels);
        return JsonResult.success();
    }
 
    /**
     * 用户修改
     * @param
     * @return
     */
    @PostMapping(MODEL + "/userUpdate.json")
    @ResponseBody
    @ApiOperation(value="用户管理(修改))", notes="test: 仅0有正确返回")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "id", value = "用户Id", required = true, dataType = "Long"),
            @ApiImplicitParam(paramType="query", name = "code", value = "用户编号不能为空", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "name", value = "用户名不能为空", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "orgId", value = "组织机构id", required = true, dataType = "Long"),
            @ApiImplicitParam(paramType="query", name = "password", value = "登陆密码", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "state", value = "状态(1:启用,2:禁用)", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "jobType0", value = "扩展例子", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "jobType1", value = "扩展例子1", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "attachmentId", value = "用户的个人资料附件,保存到Core_File 表里", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "roleId", value = "角色Id", required = true, dataType = "Long")
    })
    public JsonResult update(@RequestBody CoreUserModel model) {
        ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        CoreUser user = objectMapper.convertValue(model, CoreUser.class);
 
        ObjectMapper objectMapper1 = new ObjectMapper();
        objectMapper1.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        XzxCityPartner userParty = objectMapper1.convertValue(model, XzxCityPartner.class);
 
        boolean success = userConsoleService.updateTemplate(user);
        if(!success){
 
                userConsoleService.updateRole(user,model.getRoleId());
                success = xzxCityPartnerService.updateTemplate(userParty);
            if(success){
                this.platformService.clearFunctionCache();
                return JsonResult.success();
            }else{
                return JsonResult.failMessage("保存失败!");
 
            }
        }else{
            if (success) {
                userConsoleService.updateRole(user,model.getRoleId());
                this.platformService.clearFunctionCache();
                return JsonResult.success();
            } else {
                return JsonResult.failMessage("保存失败!");
            }
        }
 
    }
 
    /**
     * 用户添加
     * @param user
     * @return
     */
    @PostMapping(MODEL + "/userAdd.json")
    @ResponseBody
    @ApiOperation(value="用户管理(添加))", notes="test: 仅0有正确返回")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "code", value = "用户编号不能为空", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "name", value = "用户名不能为空", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "orgId", value = "组织机构id", required = true, dataType = "Long"),
            @ApiImplicitParam(paramType="query", name = "password", value = "登陆密码", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "state", value = "状态(1:启用,2:禁用)", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "jobType0", value = "扩展例子", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "jobType1", value = "扩展例子1", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "attachmentId", value = "用户的个人资料附件,保存到Core_File 表里", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "roleId", value = "角色Id", required = true, dataType = "Long")
 
    })
    public JsonResult<Long> userAdd(@RequestBody CoreUserModel user) {
        if (!platformService.isAllowUserName(user.getCode())) {
            return JsonResult.failMessage("不允许的注册名字 " + user.getCode());
        }
        user.setCreateTime(new Date());
        ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        CoreUser coreUser = objectMapper.convertValue(user, CoreUser.class);
        coreUser.setPassword("123456");
        userConsoleService.saveUser(coreUser,user.getRoleId());
 
 
        return JsonResult.success(user.getId());
    }
 
    /**
     * 用户所在公司的组织机构树
     *
     * @return
     */
    @PostMapping(MODEL + "/userOrg.do")
    @ResponseBody
    @ApiOperation(value="用户所在公司的组织机构树", notes="test: 仅0有正确返回")
    public JsonResult<List<OrgItem>> getUserCompany(HttpServletRequest request) {
            List<OrgItem> list = new ArrayList<>();
            OrgItem orgItem = platformService.getUserOrgTree();
            list.add(orgItem);
            return JsonResult.success(list);
    }
    /**
     * 组织机构列表  分页
     * @param condtion 查询条件
     * @return
     */
    @PostMapping(MODEL + "/organizationList.do")
    @ResponseBody
    @ApiOperation(value="组织机构列表  分页", notes="test: 仅0有正确返回")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "code", value = "用户编号", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "name", value = "用户名", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "type", value = "机构类型(1 集团 2 公司,3 部门,4 小组)", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "page", value = "页码", required = true, dataType = "int"),
            @ApiImplicitParam(paramType="query", name = "limit", value = "每页条数", required = true, dataType = "int"),
            @ApiImplicitParam(paramType="query", name = "parentOrgId", value = "上一级机构", required = true, dataType = "String")
    })
    public JsonResult<PageQuery<CoreOrg>> organizationList(@RequestBody OrgQuery condtion) {
        PageQuery page = condtion.getPageQuery();
        orgConsoleService.queryByCondtion(page);
        return JsonResult.success(page);
    }
 
    /**
     * 保存组织机构数据
     * @param org
     * @return
     */
    @PostMapping(MODEL + "/orgSave.json")
    @ResponseBody
    @ApiOperation(value="保存组织机构数据", notes="test: 仅0有正确返回")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "code", value = "用户编号不能为空", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "name", value = "用户名不能为空", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "type", value = "机构类型(1 集团 2 公司,3 部门,4 小组)", required = true, dataType = "Long"),
            @ApiImplicitParam(paramType="query", name = "parentOrgId", value = "上一级机构", required = true, dataType = "String")
    })
    public JsonResult<Long> orgSave(@RequestBody CoreOrg org) {
        org.setCode(org.getName());
        org.setCreateTime(new Date());
        org.setDelFlag(0);
        orgConsoleService.save(org);
        platformService.clearOrgCache();
        return JsonResult.success(org.getId());
    }
 
 
    /**
     * 更新数据
     * @param org
     * @return
     */
    @PostMapping(MODEL + "/orgUpdate.json")
    @ResponseBody
    @ApiOperation(value="更新组织机构数据", notes="test: 仅0有正确返回")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "id", value = "用户编号不能为空", required = true, dataType = "Long"),
            @ApiImplicitParam(paramType="query", name = "code", value = "用户编号不能为空", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "name", value = "用户名不能为空", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "type", value = "机构类型(1 集团 2 公司,3 部门,4 小组)", required = true, dataType = "Long"),
            @ApiImplicitParam(paramType="query", name = "parentOrgId", value = "上一级机构", required = true, dataType = "String")
    })
    public JsonResult<String> orgUpdate(@RequestBody CoreOrg org){
        //判断是否为总公司,总公司不能选择他自己作为他的父类
        CoreOrg  co  = orgConsoleService.queryById(org.getId());
 
        if(co.getParentOrgId()==null){
            if(org.getParentOrgId()!=null){
                if(org.getParentOrgId().equals(org.getId())){
                    return JsonResult.failMessage("保存失败,不能选择他自己作为父类");
                }
            }
        }else{
            if(co.getId().equals(org.getParentOrgId())){
                return JsonResult.failMessage("保存失败,不能选择他自己作为父类");
            }
        }
 
        boolean success = orgConsoleService.updateTemplate(org);
        if (success) {
            platformService.clearOrgCache();
            return JsonResult.successMessage("保存成功");
        } else {
            return JsonResult.failMessage("保存失败");
        }
    }
    /**
     * 删除组织机构
     * @param org 组织,
     * @return
     */
    @PostMapping(MODEL + "/orgDelete.json")
    @ResponseBody
    @ApiOperation(value="删除组织机构数据", notes="test: 仅0有正确返回")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "id", value = "用户编号不能为空", required = true, dataType = "Long")
    })
    public JsonResult orgDelete(@RequestBody CoreOrg org) {
        Long id = org.getId();
        List<Long> idList = new ArrayList<>();
        idList.add(id);
        orgConsoleService.deleteById(idList);
        this.platformService.clearOrgCache();
        return new JsonResult().success();
    }
    /**
     *字典列表
     * @param
     * @return
     */
    @PostMapping(MODEL + "/typeValue.do")
    @ResponseBody
    @ApiOperation(value="字典列表", notes="test: 仅0有正确返回")
    public JsonResult<List<Map<String,Object>>> typeValue(@RequestBody CoreDict dict) {
        List<CoreDict> list =coreDictService.findAllByType(dict.getType());
        List<Map<String,Object>> result = new ArrayList<>();
        for (CoreDict d:list) {
            List<Map<String,Object>> children = new ArrayList<>();
            List<CoreDict> childlist = coreDictService.findChildByParent(d.getId());
            for (CoreDict cmap:childlist) {
                Map<String,Object> m = new HashMap<>();
                m.put("id",cmap.getValue());
                m.put("name",cmap.getName());
                children.add(m);
            }
            Map<String,Object> map = new HashMap<>();
            map.put("id",d.getValue());
            map.put("name",d.getName());
            if(null!=children&&children.size()>0){
                map.put("childen",children);
            }
            result.add(map);
        }
        return JsonResult.success(result);
    }
    /**
     * 列表页、 分页数据
     *
     * @param condtion
     * @return
     */
    @PostMapping(MODEL + "/userRoleList.do")
    @ResponseBody
    @ApiOperation(value="角色管理 列表页、 分页数据", notes="test: 仅0有正确返回")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "page", value = "页码", required = true, dataType = "int"),
            @ApiImplicitParam(paramType="query", name = "limit", value = "每页条数", required = true, dataType = "int"),
            @ApiImplicitParam(paramType="query", name = "code", value = "编码", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "name", value = "名称", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "type", value = "业务角色类型(1:操作角色,2:工作流角色)", required = true, dataType = "String")
    })
    public JsonResult<PageQuery> userRoleList(@RequestBody RoleQuery condtion) {
        PageQuery page = condtion.getPageQuery();
        roleConsoleService.queryByCondtion(page);
        return JsonResult.success(page);
    }
 
    /**
     * 管理员重置用户密码
     *
     * @return
     */
    @PostMapping(MODEL + "/changeUserPassword.json")
    @ResponseBody
    @ApiOperation(value="管理员重置用户密码", notes="test: 仅0有正确返回")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "id", value = "用户ID", required = true, dataType = "Long"),
            @ApiImplicitParam(paramType="query", name = "password", value = "密码", required = true, dataType = "String")
    })
    public JsonResult changeUserPassword(@RequestBody CoreUser user) {
        userConsoleService.resetPassword(user.getId(), user.getPassword());
        return new JsonResult().success();
    }
    /**
     * 保存添加角色
     *
     * @return
     */
    @PostMapping(MODEL + "/addRole.json")
    @ResponseBody
    @ApiOperation(value="角色管理添加角色", notes="test: 仅0有正确返回")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "code", value = "角色编码", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "name", value = "角色名称", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "type", value = "角色类型,系统的角色,工作流角色(R0,R1...)", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "ids", value = "角色Id,多个用逗号隔开", required = true, dataType = "String")
    })
    public JsonResult addRole(@RequestBody CoreRole role) {
        CoreRole role1 = roleConsoleService.queryByCode(role.getCode());
        if (role1 != null) {
            return JsonResult.failMessage("用户编号已存在");
        }
        JsonResult result = new JsonResult();
        role.setCreateTime(new Date());
        role.setDelFlag("0");
        roleConsoleService.save(role);
        platformService.clearFunctionCache();
        return result.success();
    }
    /**
     * 更新角色
     *
     * @param role
     * @return
     */
    @PostMapping(MODEL + "/updateRole.json")
    @ResponseBody
    @ApiOperation(value="角色管理更新角色", notes="test: 仅0有正确返回")
    public JsonResult<String> updateRole(@RequestBody CoreRole role) {
        role.setDelFlag("0");
        boolean success = roleConsoleService.update(role);
        if (success) {
            platformService.clearFunctionCache();
            return new JsonResult().success();
        } else {
            return JsonResult.failMessage("保存失败");
        }
    }
    /**
     * (批量)删除角色
     *
     * @param model
     *            角色id
     * @return
     */
    @PostMapping(MODEL + "/deleteRole.json")
    @ResponseBody
    @ApiOperation(value="角色管理删除角色", notes="test: 仅0有正确返回")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "ids", value = "角色Id", required = true, dataType = "String")
    })
    public JsonResult deleteRole(@RequestBody CoreRoleModel model) {
        String ids = model.getIds();
        if (ids.endsWith(",")) {
            ids = StringUtils.substringBeforeLast(ids, ",");
        }
 
        List<Long> idList = ConvertUtil.str2longs(ids);
        Long id = idList.get(0);
        CoreRole cr = roleConsoleService.queryById(id);
        cr.setDelFlag("1");
        roleConsoleService.update(cr);
        return new JsonResult().success();
    }
 
    @PostMapping(MODEL + "/dictList.json")
    @ResponseBody
    @ApiOperation(value="组织机构列表", notes="test: 仅0有正确返回")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "type", value = "类型(org_type:组织机构)", required = true, dataType = "String")
    })
    public JsonResult<List<Map<String,Object>>> dictList(@RequestBody CoreDictQuery condtion)
    {
        condtion.setPage(Integer.parseInt("1"));
        condtion.setLimit(Integer.parseInt("100"));
        PageQuery page = condtion.getPageQuery();
        dictService.queryByCondition(page);
        return JsonResult.success(page.getList());
    }
 
    @RequestMapping(MODEL + "/functionList.json")
    @ResponseBody
    @ApiOperation(value="功能点管理", notes="test: 仅0有正确返回")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "page", value = "页码", required = true, dataType = "int"),
            @ApiImplicitParam(paramType="query", name = "limit", value = "每页条数", required = true, dataType = "int"),
            @ApiImplicitParam(paramType="query", name = "code", value = "代码", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "name", value = "名称", required = true, dataType = "String")
    })
    public JsonResult<PageQuery<CoreFunction>> functionList(@RequestBody FunctionQuery condtion) {
        PageQuery page = condtion.getPageQuery();
        functionConsoleService.queryByCondtion(page);
        return JsonResult.success(page);
    }
 
}