郑永安
2023-06-19 f65443d8abeaedc9d102324565e8368e7c9d90c8
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
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
package com.gk.firework.Controller;
 
import com.alibaba.fastjson.JSONObject;
import com.gk.firework.Controller.Base.BaseController;
import com.gk.firework.Domain.DTO.JiangWaiDeadlineReqDTO;
import com.gk.firework.Domain.DistrictInfo;
import com.gk.firework.Domain.Enterprise;
import com.gk.firework.Domain.Exception.BusinessException;
import com.gk.firework.Domain.UserInfo;
import com.gk.firework.Domain.UserRolesInfo;
import com.gk.firework.Domain.Utils.*;
import com.gk.firework.Service.*;
import io.swagger.annotations.*;
import org.apache.catalina.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
 
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.*;
 
@Api(tags = "用户管理数据接口")
@RestController
public class UserController extends BaseController {
 
    @Autowired
    UserService userService;
    @Autowired
    RoleService roleService;
    @Autowired
    UserRolesService userRolesService;
    @Autowired
    RolePermissionsService rolePermissionsService;
    @Autowired
    ExcelExportService excelExportService;
    @Autowired
    DistrictService districtService;
    @Autowired
    UserRolesService userRolesInfoService;
    @Autowired
    EnterpriseService enterpriseService;
    @Autowired
    UserDeadlineService userDeadlineService;
 
    @Value("${filePath}")
    private String filePath; //配置文件配置的物理保存地址
 
    @GetMapping("/user")
    @ApiOperation(value = "获取用户数据",response = Msg.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageIndex",value = "当前页码"),
            @ApiImplicitParam(name = "pageSize",value = "每页行数"),
            @ApiImplicitParam(name = "sort",value = "排序规则"),
            @ApiImplicitParam(name = "order",value = "排序字段"),
            @ApiImplicitParam(name = "username",value = "用户名"),
            @ApiImplicitParam(name = "company",value = "单位"),
            @ApiImplicitParam(name = "department",value = "部门"),
            @ApiImplicitParam(name = "job",value = "职务"),
            @ApiImplicitParam(name = "type",value = "用户类型"),
            @ApiImplicitParam(name = "province",value = "省份"),
            @ApiImplicitParam(name = "city",value = "城市"),
            @ApiImplicitParam(name = "area",value = "区县"),
            @ApiImplicitParam(name = "town",value = "乡镇"),
            @ApiImplicitParam(name = "community",value = "社区"),
    })
    public Msg getUserInfo(@RequestParam(defaultValue = "0") Integer pageIndex, @RequestParam(defaultValue = "10") Integer pageSize, String sort,String order,
                                    String username,String company, String department, String job,Byte type,
                           String province, String city, String area, String town, String community){
        Msg msg = new Msg();
        msg.setCode("200");
        msg.setMessage("success");
 
        PageInfo pageInfo = new PageInfo(pageIndex, pageSize,sort,order);
        HashMap<String, Object> condition = new HashMap<String, Object>();
 
        if (StringUtils.isNotBlank(username)) {
            condition.put("username", username.trim());
        }
 
        if (StringUtils.isNotBlank(company)) {
            condition.put("company", company.trim());
        }
 
        if (StringUtils.isNotBlank(department)) {
            condition.put("department", department.trim());
        }
 
        if (StringUtils.isNotBlank(job)){
            condition.put("job",job.trim());
        }
 
        if (type != null){
            condition.put("type",type);
        }
 
        if (StringUtils.isNotBlank(province)){
            condition.put("province",province.trim());
        }
 
        if (StringUtils.isNotBlank(city)){
            condition.put("city",city.trim());
        }
 
        if (StringUtils.isNotBlank(area)){
            condition.put("area",area.trim());
        }
 
        if (StringUtils.isNotBlank(town)){
            condition.put("town",town.trim());
        }
 
        if (StringUtils.isNotBlank(community)){
            condition.put("community",community.trim());
        }
 
        UserInfo userInfo = userService.selectByUser(getUser().getUsername());
        if (StringUtils.isNotBlank(userInfo.getCompanynumber())){
            condition.put("username", userInfo.getUsername());
        }else{
            condition.put("provinceSee", userInfo.getProvince());
            condition.put("citySee",userInfo.getCity());
            condition.put("areaSee",userInfo.getArea());
            condition.put("townSee",userInfo.getTown());
            condition.put("communitySee",userInfo.getCommunity());
        }
 
        condition.put("iscompany",(byte)0);
        condition.put("issale",(byte)0);
        pageInfo.setCondition(condition);
        userService.selectUserDataGrid(pageInfo);
        msg.setResult(pageInfo);
        return msg;
    }
 
    @PostMapping("/adduser")
    @ApiOperation(value = "添加用户数据",response = Msg.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "username",value = "用户名",required = true),
            @ApiImplicitParam(name = "password",value = "密码",required = true),
            @ApiImplicitParam(name = "type",value = "用户类型",required = true),
            @ApiImplicitParam(name = "email",value = "邮箱"),
            @ApiImplicitParam(name = "phone",value = "办公电话"),
            @ApiImplicitParam(name = "mobile",value = "手机号"),
            @ApiImplicitParam(name = "company",value = "单位"),
            @ApiImplicitParam(name = "department",value = "部门"),
            @ApiImplicitParam(name = "job",value = "职务"),
            @ApiImplicitParam(name = "createdby",value = "创建人"),
            @ApiImplicitParam(name = "province",value = "省份"),
            @ApiImplicitParam(name = "city",value = "城市"),
            @ApiImplicitParam(name = "area",value = "区县"),
            @ApiImplicitParam(name = "town",value = "乡镇"),
            @ApiImplicitParam(name = "community",value = "社区"),
    })
    public Msg addUserInfo(@RequestBody JSONObject jsonObject){
        Msg msg = new Msg();
        msg.setCode("200");
        msg.setMessage("success");
        UserInfo userInfo = new UserInfo();
        userInfo.setUsername(jsonObject.getString("username"));
        String password = jsonObject.getString("password");
        String PW_PATTERN = "(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*[~!@#$%^&*_.]).{8,}";
        if (!password.matches(PW_PATTERN)){
            msg.setCode("500");
            msg.setMessage("密码必须8位以上,并且包含大小写字母、数字、特殊符号三种以上");
            return msg;
        }else {
            userInfo.setPassword(Base64Encrypt.encode(password.getBytes()));
        }
        String mobile = jsonObject.getString("mobile");
        if (StringUtils.isNotBlank(mobile) && mobile.length() == 11){
            userInfo.setMobile(mobile);
        }else if (StringUtils.isNotBlank(mobile)){
            msg.setCode("500");
            msg.setMessage("手机号必须为11位数");
            return msg;
        }
        try {
            userInfo.setType(jsonObject.getInteger("type"));
        }catch (Exception e) {
            msg.setCode("500");
            msg.setMessage("用户类型必须为数字");
            return msg;
        }
        userInfo.setEmail(jsonObject.getString("email"));
        userInfo.setPhone(jsonObject.getString("phone"));
        userInfo.setCompany(jsonObject.getString("company"));
        userInfo.setDepartment(jsonObject.getString("department"));
        userInfo.setJob(jsonObject.getString("job"));
        userInfo.setCreatedby(jsonObject.getString("createdby"));
        userInfo.setCreateddate(new Date());
        userInfo.setLastmodifiedby(jsonObject.getString("createdby"));
        userInfo.setLastmodifieddate(new Date());
        userInfo.setProvince(jsonObject.getString("province"));
        userInfo.setCity(jsonObject.getString("city"));
        userInfo.setArea(jsonObject.getString("area"));
        userInfo.setTown(jsonObject.getString("town"));
        userInfo.setCommunity(jsonObject.getString("community"));
        userInfo.setCode(jsonObject.getString("code"));
        userInfo.setIsdel((byte)0);
        userInfo.setIssale((byte)0);
        UserInfo userInfoExist = userService.selectByUser(userInfo.getUsername());
        if (null != userInfoExist){
            msg.setCode("500");
            msg.setMessage("用户名重复");
            return msg;
        }else {
            userService.save(userInfo);
        }
        return msg;
    }
 
    @PostMapping("/importUser")
    @ApiOperation(value = "导入用户数据",response = Msg.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "file",value = "文件",required = true),
            @ApiImplicitParam(name = "operator",value = "操作人",required = true),
    })
    @ResponseBody
    public Msg importUser(String operator,MultipartFile file){
        Msg msg = new Msg();
        msg.setCode("200");
        msg.setMessage("success");
 
        String filesave ="";
        try {
            SimpleDateFormat sdf = new SimpleDateFormat( "yyyyMMddHHmmssSSS" );
            if (file == null)
            {
                msg.setCode("404");
                msg.setMessage("未找到上传文件");
                return msg;
            }
 
            long size = file.getSize();
            if(0 == size)
            {
                msg.setCode("404");
                msg.setMessage("上传文件大小为空");
                return msg;
            }
 
            if(!FileOptUtils.isDirExists(filePath)){
                msg.setCode("500");
                msg.setMessage("发生错误或不为目录");
                return msg;
            }
 
            filesave = filePath + operator + "_" + sdf.format(new Date()) +".xlsx";
 
            file.transferTo(new File(filesave));
            InputStream in = new FileInputStream(filesave);
            String name = file.getOriginalFilename();
            Boolean isExcel2007 = name.substring(name.lastIndexOf(".") + 1).endsWith("xlsx")? true:false;
            BooleanReason blret = excelExportService.importUserExcel(in,operator,isExcel2007);
            if(blret.getValue().equals(false))
            {
                msg.setCode("500");
                msg.setMessage(blret.getResultmsg());
                return msg;
            }
        } catch (Exception e) {
            e.printStackTrace();
            msg.setCode("500");
            msg.setMessage("导入发生错误");
            return msg;
        }
 
        return msg;
    }
 
 
    @PostMapping("/importUserCode")
    @ApiOperation(value = "导入用户数据",response = Msg.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "file",value = "文件",required = true),
            @ApiImplicitParam(name = "operator",value = "操作人",required = true),
    })
    @ResponseBody
    public Msg importUserCode(String operator,MultipartFile file){
        Msg msg = new Msg();
        msg.setCode("200");
        msg.setMessage("success");
 
        String filesave ="";
        try {
            SimpleDateFormat sdf = new SimpleDateFormat( "yyyyMMddHHmmssSSS" );
            if (file == null)
            {
                msg.setCode("404");
                msg.setMessage("未找到上传文件");
                return msg;
            }
 
            long size = file.getSize();
            if(0 == size)
            {
                msg.setCode("404");
                msg.setMessage("上传文件大小为空");
                return msg;
            }
 
            if(!FileOptUtils.isDirExists(filePath)){
                msg.setCode("500");
                msg.setMessage("发生错误或不为目录");
                return msg;
            }
 
            filesave = filePath + operator + "_" + sdf.format(new Date()) +".xlsx";
 
            file.transferTo(new File(filesave));
            InputStream in = new FileInputStream(filesave);
            String name = file.getOriginalFilename();
            Boolean isExcel2007 = name.substring(name.lastIndexOf(".") + 1).endsWith("xlsx")? true:false;
            BooleanReason blret = excelExportService.importUserCodeExcel(in,operator,isExcel2007);
            if(blret.getValue().equals(false))
            {
                msg.setCode("500");
                msg.setMessage(blret.getResultmsg());
                return msg;
            }
        } catch (Exception e) {
            e.printStackTrace();
            msg.setCode("500");
            msg.setMessage("导入发生错误");
            return msg;
        }
 
        return msg;
    }
 
 
    @PostMapping("/putuser")
    @ApiOperation(value = "修改用户数据",response = Msg.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "用户id",required = true),
            @ApiImplicitParam(name = "username",value = "用户名",required = true),
            @ApiImplicitParam(name = "password",value = "密码"),
            @ApiImplicitParam(name = "type",value = "用户类型",required = true),
            @ApiImplicitParam(name = "email",value = "邮箱"),
            @ApiImplicitParam(name = "phone",value = "办公电话"),
            @ApiImplicitParam(name = "mobile",value = "手机号"),
            @ApiImplicitParam(name = "company",value = "单位"),
            @ApiImplicitParam(name = "department",value = "部门"),
            @ApiImplicitParam(name = "job",value = "职务"),
            @ApiImplicitParam(name = "lastmodifiedby",value = "更新人"),
            @ApiImplicitParam(name = "province",value = "省份"),
            @ApiImplicitParam(name = "city",value = "城市"),
            @ApiImplicitParam(name = "area",value = "区县"),
            @ApiImplicitParam(name = "town",value = "乡镇"),
            @ApiImplicitParam(name = "community",value = "社区"),
    })
    public Msg putUserInfo(@RequestBody JSONObject jsonObject){
        Msg msg = new Msg();
        msg.setCode("200");
        msg.setMessage("success");
        Long id = jsonObject.getLong("id");
        String username = jsonObject.getString("username");
        List<UserInfo> userList = userService.selectUserInfo(id,username);
        if (userList.size() > 0){
            msg.setCode("500");
            msg.setMessage("用户名重复");
            return msg;
        }
        UserInfo userInfo = new UserInfo();
        userInfo.setId(jsonObject.getLong("id"));
        userInfo.setUsername(jsonObject.getString("username"));
        String password = jsonObject.getString("password");
        String PW_PATTERN = "(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*[~!@#$%^&*_.]).{8,}";
        if (StringUtils.isNotBlank(password)&& !password.matches(PW_PATTERN)){
            msg.setCode("500");
            msg.setMessage("密码必须8位以上,并且包含大小写字母、数字、特殊符号三种以上");
            return msg;
        }else if(StringUtils.isNotBlank(password)){
            userInfo.setPassword(Base64Encrypt.encode(password.getBytes()));
        }
        String mobile = jsonObject.getString("mobile");
        if (StringUtils.isNotBlank(mobile) && mobile.length() == 11){
            userInfo.setMobile(mobile);
        }else if (StringUtils.isNotBlank(mobile)){
            msg.setCode("500");
            msg.setMessage("手机号必须为11位数");
            return msg;
        }
        try {
            userInfo.setType(jsonObject.getInteger("type"));
        }catch (Exception e) {
            msg.setCode("500");
            msg.setMessage("用户类型必须为数字");
            return msg;
        }
        userInfo.setEmail(jsonObject.getString("email"));
        userInfo.setPhone(jsonObject.getString("phone"));
        userInfo.setCompany(jsonObject.getString("company"));
        userInfo.setDepartment(jsonObject.getString("department"));
        userInfo.setJob(jsonObject.getString("job"));
        userInfo.setCreatedby(jsonObject.getString("lastmodifiedby"));
        userInfo.setCreateddate(new Date());
        userInfo.setLastmodifiedby(jsonObject.getString("lastmodifiedby"));
        userInfo.setLastmodifieddate(new Date());
        userInfo.setProvince(jsonObject.getString("province"));
        userInfo.setCity(jsonObject.getString("city"));
        userInfo.setArea(jsonObject.getString("area"));
        userInfo.setTown(jsonObject.getString("town"));
        userInfo.setCommunity(jsonObject.getString("community"));
        userInfo.setCode(jsonObject.getString("code"));
        userService.updateById(userInfo);
        // 如果修改为新疆企业 会重置 截止日期
        String province = jsonObject.getString("province");
        // 不修改原代码 无论怎样 是新疆 就重置
        UserInfo company = userService.getById(userInfo.getId());
        if (company.getCompanyid() != null) {
            userService.updateDeadline2NullByComapnyId(company.getCompanyid());
        }
        return msg;
 
    }
 
 
    @PostMapping("/jiangWai/deadline/set")
    public Msg updateJinagWaiDeadline(@RequestBody JiangWaiDeadlineReqDTO reqDTO) {
        userService.updateDeadline(reqDTO,getUser());
        return success();
    }
 
 
    @PostMapping("/userroles")
    @ApiOperation(value = "修改用户角色",response = Msg.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "用户id",required = true),
            @ApiImplicitParam(name = "roles",value = "用户名",required = true),
 
    })
    public Msg updateUserRole(@RequestBody JSONObject jsonObject){
        Msg msg = new Msg();
        msg.setCode("200");
        msg.setMessage("success");
        Long userid = jsonObject.getLong("id");
        String roles = jsonObject.getString("roles");
        if (StringUtils.isNotBlank(roles)){
            userRolesInfoService.deleteByUserId(userid);
            roles = roles.replace("[","").replace("]","");
            List<String> list = StringUtils.toList(roles);
            for (String role : list){
                UserRolesInfo userRolesInfo = new UserRolesInfo();
                userRolesInfo.setUserid(userid);
                userRolesInfo.setRoleid(Long.parseLong(role.trim()));
                userRolesInfoService.save(userRolesInfo);
            }
        }
        return msg;
 
    }
 
    @PostMapping("/deluser")
    @ApiOperation(value = "删除用户数据", notes = "删除用户数据", response = Msg.class)
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query",name = "id",value = "id",required = true),
            @ApiImplicitParam(paramType="body",name = "lastmodifiedby",value = "更新人"),
 
    })
    public Msg delUserInfo(@ApiParam(value = "id,lastmodifiedby")
                             @RequestBody JSONObject jsonObject){
        Msg msg = new Msg();
        msg.setCode("200");
        msg.setMessage("success");
        UserInfo userInfo = new UserInfo();
        userInfo.setId(jsonObject.getLong("id"));
        userInfo.setLastmodifiedby(jsonObject.getString("lastmodifiedby"));
        userInfo.setLastmodifieddate(new Date());
        userInfo.setIsdel((byte)1);
        userService.updateById(userInfo);
        return msg;
    }
 
    @PostMapping("/importDistrict")
    @ApiOperation(value = "导入省市数据",response = Msg.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "file",value = "文件",required = true),
            @ApiImplicitParam(name = "operator",value = "操作人",required = true),
    })
    @ResponseBody
    public Msg importDistrict(String operator,MultipartFile file){
        Msg msg = new Msg();
        msg.setCode("200");
        msg.setMessage("success");
 
        String filesave ="";
        try {
            SimpleDateFormat sdf = new SimpleDateFormat( "yyyyMMddHHmmssSSS" );
            if (file == null)
            {
                msg.setCode("404");
                msg.setMessage("未找到上传文件");
                return msg;
            }
 
            long size = file.getSize();
            if(0 == size)
            {
                msg.setCode("404");
                msg.setMessage("上传文件大小为空");
                return msg;
            }
 
            if(!FileOptUtils.isDirExists(filePath)){
                msg.setCode("500");
                msg.setMessage("发生错误或不为目录");
                return msg;
            }
 
            filesave = filePath + operator + "_" + sdf.format(new Date()) +".xlsx";
 
            file.transferTo(new File(filesave));
            InputStream in = new FileInputStream(filesave);
            String name = file.getOriginalFilename();
            Boolean isExcel2007 = name.substring(name.lastIndexOf(".") + 1).endsWith("xlsx")? true:false;
            BooleanReason blret = excelExportService.importDistrictExcel(in,operator,isExcel2007);
            if(blret.getValue().equals(false))
            {
                msg.setCode("500");
                msg.setMessage(blret.getResultmsg());
                return msg;
            }
        } catch (Exception e) {
            e.printStackTrace();
            msg.setCode("500");
            msg.setMessage("导入发生错误");
            return msg;
        }
 
        return msg;
    }
 
    @GetMapping("/district")
    @ApiOperation(value = "获取省市区数据",response = Msg.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type",value = "类型"),
            @ApiImplicitParam(name = "parentname",value = "上级名称"),
            @ApiImplicitParam(name = "parenttype",value = "上级类型"),
    })
    public Msg getdistrictInfo(String type,String parentname,String parenttype){
        Msg msg = new Msg();
        msg.setCode("200");
        msg.setMessage("success");
        List<DistrictInfo> districtInfoList = new ArrayList<> ();
        if (parenttype.equals("0")){
            districtInfoList = districtService.selectDistrictInfo(type, parenttype);
        }else {
            districtInfoList = districtService.selectDistrictByName(type,parentname,parenttype);
        }
        msg.setResult(districtInfoList);
        return msg;
    }
 
    @GetMapping("/districtByName")
    @ApiOperation(value = "获取省市区数据",response = Msg.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "province",value = "省份"),
            @ApiImplicitParam(name = "city",value = "城市"),
            @ApiImplicitParam(name = "area",value = "区县"),
            @ApiImplicitParam(name = "town",value = "街道"),
            @ApiImplicitParam(name = "community",value = "社区"),
    })
    public Msg getDistrictByName(String province,String city,String area,String town,String community){
        Msg msg = new Msg();
        msg.setCode("200");
        msg.setMessage("success");
 
        if (StringUtils.isBlank(province)){
            List<DistrictInfo> provinceList = districtService.selectDistrictInfo("1", "0");
            Map<String,Object> map = new HashMap<> ();
            map.put("provinceList",provinceList);
            msg.setResult(map);
        }else if (StringUtils.isBlank(city)){
            List<DistrictInfo> provinceList = districtService.selectDistrictInfo("1", "0");
            DistrictInfo provinceInfo = districtService.selectInfoByName(province,(byte)1);
            List<DistrictInfo> cityList = districtService.selectDistrictInfo("2", provinceInfo.getCode());
            Map<String,Object> map = new HashMap<> ();
            map.put("provinceList",provinceList);
            map.put("cityList",cityList);
            msg.setResult(map);
        }else if (StringUtils.isBlank(area)){
            List<DistrictInfo> provinceList = districtService.selectDistrictInfo("1", "0");
            DistrictInfo provinceInfo = districtService.selectInfoByName(province,(byte)1);
            List<DistrictInfo> cityList = districtService.selectDistrictInfo("2", provinceInfo.getCode());
            DistrictInfo cityInfo = districtService.selectInfoByName(city,(byte)2);
            List<DistrictInfo> areaList = districtService.selectDistrictInfo("3", cityInfo.getCode());
            Map<String,Object> map = new HashMap<> ();
            map.put("provinceList",provinceList);
            map.put("cityList",cityList);
            map.put("areaList",areaList);
            msg.setResult(map);
        }else if (StringUtils.isBlank(town)){
            List<DistrictInfo> provinceList = districtService.selectDistrictInfo("1", "0");
            DistrictInfo provinceInfo = districtService.selectInfoByName(province,(byte)1);
            List<DistrictInfo> cityList = districtService.selectDistrictInfo("2", provinceInfo.getCode());
            DistrictInfo cityInfo = districtService.selectInfoByName(city,(byte)2);
            List<DistrictInfo> areaList = districtService.selectDistrictInfo("3", cityInfo.getCode());
            DistrictInfo areaInfo = districtService.selectInfoByName(area,(byte)3);
            List<DistrictInfo> townList = districtService.selectDistrictInfo("4", areaInfo.getCode());
 
            Map<String,Object> map = new HashMap<> ();
            map.put("provinceList",provinceList);
            map.put("cityList",cityList);
            map.put("areaList",areaList);
            map.put("townList",townList);
            msg.setResult(map);
        }else{
            List<DistrictInfo> provinceList = districtService.selectDistrictInfo("1", "0");
            DistrictInfo provinceInfo = districtService.selectInfoByName(province,(byte)1);
            List<DistrictInfo> cityList = districtService.selectDistrictInfo("2", provinceInfo.getCode());
            DistrictInfo cityInfo = districtService.selectInfoByName(city,(byte)2);
            List<DistrictInfo> areaList = districtService.selectDistrictInfo("3", cityInfo.getCode());
            DistrictInfo areaInfo = districtService.selectInfoByName(area,(byte)3);
            List<DistrictInfo> townList = districtService.selectDistrictInfo("4", areaInfo.getCode());
            DistrictInfo townInfo = districtService.selectInfoByName(town,(byte)4);
            List<DistrictInfo> communityList = districtService.selectDistrictInfo("5", townInfo.getCode());
 
            Map<String,Object> map = new HashMap<> ();
            map.put("provinceList",provinceList);
            map.put("cityList",cityList);
            map.put("areaList",areaList);
            map.put("townList",townList);
            map.put("communityList",communityList);
            msg.setResult(map);
        }
        return msg;
    }
 
    @GetMapping("/enterpriseUser")
    @ApiOperation(value = "获取企业用户数据",response = Msg.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageIndex",value = "当前页码"),
            @ApiImplicitParam(name = "pageSize",value = "每页行数"),
            @ApiImplicitParam(name = "sort",value = "排序规则"),
            @ApiImplicitParam(name = "order",value = "排序字段"),
            @ApiImplicitParam(name = "username",value = "用户名"),
            @ApiImplicitParam(name = "company",value = "单位"),
            @ApiImplicitParam(name = "department",value = "部门"),
            @ApiImplicitParam(name = "job",value = "职务"),
            @ApiImplicitParam(name = "type",value = "用户类型"),
            @ApiImplicitParam(name = "province",value = "省份"),
            @ApiImplicitParam(name = "city",value = "城市"),
            @ApiImplicitParam(name = "area",value = "区县"),
            @ApiImplicitParam(name = "town",value = "乡镇"),
            @ApiImplicitParam(name = "community",value = "社区"),
    })
    public Msg getEnterpriseUserInfo(@RequestParam(defaultValue = "0") Integer pageIndex, @RequestParam(defaultValue = "10") Integer pageSize, String sort,String order,
                           String username,String company, String department, String job,Byte type, String province, String city, String area, String town, String community){
        Msg msg = new Msg();
        msg.setCode("200");
        msg.setMessage("success");
 
        PageInfo pageInfo = new PageInfo(pageIndex, pageSize,sort,order);
        HashMap<String, Object> condition = new HashMap<String, Object>();
 
        if (StringUtils.isNotBlank(username)) {
            condition.put("username", username.trim());
        }
 
        if (StringUtils.isNotBlank(company)) {
            condition.put("company", company.trim());
        }
 
        if (StringUtils.isNotBlank(department)) {
            condition.put("department", department.trim());
        }
 
        if (StringUtils.isNotBlank(job)){
            condition.put("job",job.trim());
 
        }
        if (type != null){
            condition.put("type",type);
        }
        UserInfo userInfo = userService.getById(getUser().getId());
        if (userInfo.getCompanyid() != null){
            condition.put("companyid", userInfo.getCompanyid());
        }else if (userInfo.getType() == 3){
            condition.put("province",userInfo.getProvince());
            condition.put("city",userInfo.getCity());
            condition.put("area",userInfo.getArea());
            condition.put("town",userInfo.getTown());
            condition.put("community",userInfo.getCommunity());
        }
 
        if (StringUtils.isNotBlank(province) && condition.get("province") == null) {
            condition.put("province", province.trim());
            if (StringUtils.isNotBlank(city)) {
                condition.put("city", city.trim());
            }
 
            if (StringUtils.isNotBlank(area)) {
                condition.put("area", area.trim());
            }
 
            if (StringUtils.isNotBlank(town)) {
                condition.put("town", town.trim());
            }
 
            if (StringUtils.isNotBlank(community)) {
                condition.put("community", community.trim());
            }
        }
        condition.put("iscompany",(byte)1);
        condition.put("issale",(byte)0);
        pageInfo.setCondition(condition);
        userService.selectUserDataGrid(pageInfo);
        msg.setResult(pageInfo);
        return msg;
    }
 
    @GetMapping("/saleUser")
    @ApiOperation(value = "获取终端机用户数据",response = Msg.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageIndex",value = "当前页码"),
            @ApiImplicitParam(name = "pageSize",value = "每页行数"),
            @ApiImplicitParam(name = "sort",value = "排序规则"),
            @ApiImplicitParam(name = "order",value = "排序字段"),
            @ApiImplicitParam(name = "username",value = "用户名"),
            @ApiImplicitParam(name = "company",value = "单位"),
            @ApiImplicitParam(name = "department",value = "部门"),
            @ApiImplicitParam(name = "job",value = "职务"),
            @ApiImplicitParam(name = "type",value = "用户类型"),
            @ApiImplicitParam(name = "province",value = "省份"),
            @ApiImplicitParam(name = "city",value = "城市"),
            @ApiImplicitParam(name = "area",value = "区县"),
            @ApiImplicitParam(name = "town",value = "乡镇"),
            @ApiImplicitParam(name = "community",value = "社区"),
    })
    public Msg getSaleUserInfo(@RequestParam(defaultValue = "0") Integer pageIndex, @RequestParam(defaultValue = "10") Integer pageSize, String sort,String order,
                                     String username,String company, String department, String job,Byte type, String province, String city, String area, String town, String community,
                               String safetySuperVision){
        Msg msg = new Msg();
        msg.setCode("200");
        msg.setMessage("success");
 
        PageInfo pageInfo = new PageInfo(pageIndex, pageSize,sort,order);
        HashMap<String, Object> condition = new HashMap<String, Object>();
 
        if (StringUtils.isNotBlank(username)) {
            condition.put("username", username.trim());
        }
 
        if (StringUtils.isNotBlank(company)) {
            condition.put("company", company.trim());
        }
 
        if (StringUtils.isNotBlank(department)) {
            condition.put("department", department.trim());
        }
 
        if (StringUtils.isNotBlank(job)){
            condition.put("job",job.trim());
 
        }
        if (type != null){
            condition.put("type",type);
        }
        UserInfo userInfo = userService.getById(getUser().getId());
        if (userInfo.getCompanyid() != null){
            condition.put("companyid", userInfo.getCompanyid());
        }else if (userInfo.getType() == 3){
            condition.put("province",userInfo.getProvince());
            condition.put("city",userInfo.getCity());
            condition.put("area",userInfo.getArea());
            condition.put("town",userInfo.getTown());
            condition.put("community",userInfo.getCommunity());
        }
 
        if (StringUtils.isNotBlank(province) && condition.get("province") == null) {
            condition.put("province", province.trim());
            if (StringUtils.isNotBlank(city)) {
                condition.put("city", city.trim());
            }
 
            if (StringUtils.isNotBlank(area)) {
                condition.put("area", area.trim());
            }
 
            if (StringUtils.isNotBlank(town)) {
                condition.put("town", town.trim());
            }
 
            if (StringUtils.isNotBlank(community)) {
                condition.put("community", community.trim());
            }
        }
        condition.put("safetysupervision",safetySuperVision);
        condition.put("iscompany",(byte)1);
        condition.put("issale",(byte)1);
        pageInfo.setCondition(condition);
        userService.selectUserDataGrid(pageInfo);
        msg.setResult(pageInfo);
        return msg;
    }
 
}