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
package com.consum.base.controller;
 
import java.io.IOException;
import java.io.InputStream;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.TreeMap;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.InputStreamResource;
import org.springframework.core.io.Resource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
 
import com.alibaba.excel.EasyExcelFactory;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.excel.exception.ExcelDataConvertException;
import com.alibaba.excel.read.metadata.holder.ReadSheetHolder;
import com.consum.base.BaseController;
import com.consum.base.core.utils.CommonUtil;
import com.consum.base.core.utils.FinSysTenantUtils;
import com.consum.base.pojo.FinSysTenantParam;
import com.consum.base.pojo.FinSysTenantSearchParam;
import com.consum.base.pojo.excel.ImportTenantTemplate;
import com.consum.base.service.FinSysTenantService;
import com.consum.base.service.FinSysTenantUserService;
import com.consum.model.po.FinSysTenant;
import com.consum.model.po.FinSysTenantUser;
import com.consum.model.vo.FinSysTenantUserResult;
import com.walker.db.page.GenericPager;
import com.walker.infrastructure.tree.TreeNode;
import com.walker.infrastructure.utils.StringUtils;
import com.walker.web.ResponseValue;
 
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
 
/**
 * @Description 机构
 * @Author wh
 * @Date 2023/7/13 19:51
 */
@Api(value = "机构管理", tags = "机构管理")
@RestController
@RequestMapping("/pc/fin/sys/tenant")
public class FinSysTenantController extends BaseController {
 
    private FinSysTenantService finSysTenantService;
 
    @Autowired
    private FinSysTenantUserService finSysTenantUserService;
 
    @Autowired
    public FinSysTenantController(FinSysTenantService finSysTenantService) {
        this.finSysTenantService = finSysTenantService;
    }
 
    @Value("${iplatform.file.file-root}")
    private String filePath;
 
    private boolean multiRoot = true;
    private TreeNode dummyRoot = null;
    private Map<Long, TreeNode> rootMap = new TreeMap();
    private Map<Long, TreeNode> childMap = new TreeMap();
    private long defaultParentId = 0L;
 
    /**
     * @Description 获取机构树
     * @Author wh
     * @Date 2023/7/11 11:15
     */
    @GetMapping("/select/tree_fin_tenant")
    public ResponseValue listOrgRootTree() {
        // 系统用户
        FinSysTenantUser user = this.getSysInfo();
        if (Objects.isNull(user)) {
            return ResponseValue.error("登录用户信息不存在");
        }
 
        // 获取所有机构
        List<FinSysTenant> finSysTenantList = this.finSysTenantService.queryForTree();
        // 根据登陆人id获取系统用户,如果有系统用户时
        // 获取当前用户信息
        String tenantId = user.getTenantId();
        FinSysTenant finSysTenant = new FinSysTenant();
        finSysTenant.setId(new Long(tenantId));
        // 主键是TempId
        finSysTenant.setTempId(new Long(tenantId));
        // 查询当前用户的机构
        FinSysTenant userTenant = finSysTenantService.get(finSysTenant);
        // 树列表
        List<TreeNode> treeRootList;
        if (userTenant != null) {
            if (userTenant.getLv() != 1 && userTenant.getParentId() != 0) {
                rootMap.clear();
                this.childMap.clear();
                this.defaultParentId = new Long(user.getTenantId());
                // 根据父级获取子集
                setEntityList(finSysTenantList);
                treeRootList = getTreeRootList();
            } else {
                treeRootList = FinSysTenantUtils.getFinSysTenantTree(finSysTenantList);
            }
        } else {
            treeRootList = FinSysTenantUtils.getFinSysTenantTree(finSysTenantList);
        }
 
        if (StringUtils.isEmptyList(treeRootList)) {
            logger.error("未找到任何顶级区划树列表: treeNodeList = null");
        } else {
            logger.debug(treeRootList.toString());
        }
        return ResponseValue.success(treeRootList);
    }
 
    /**
     * @Description 分页列表查询
     * @Author llb
     * @Date 2023/7/14 13:59
     */
    @RequestMapping("/select/list")
    public ResponseValue allocatedList() {
        FinSysTenantSearchParam param = CommonUtil.getObjFromReq(FinSysTenantSearchParam.class);
        FinSysTenantSearchParam param2 = new FinSysTenantSearchParam();
        CommonUtil.copyProperties(param, param2);
        param = param2;
 
        FinSysTenantUser sysInfo = getSysInfo();
        if (sysInfo == null) {
            return ResponseValue.error("登录用户信息不存在");
        }
        GenericPager<FinSysTenant> pager = null;
        StringBuilder whStr = new StringBuilder("where 1=1 and is_delete = 0 ");
        HashMap<String, Object> paramts = new HashMap<>();
        if (param.getTenantId() == null) {
            if (sysInfo.getLv() != 1) {
                whStr.append(" and parent_id=:parent_id");
                paramts.put("parent_id", sysInfo.getTenantId());
            }
        }
        if (param.getStatus() != null) {
            whStr.append(" and status = :status");
            paramts.put("status", param.getStatus());
        }
        if (param.getTenantId() != null && param.getTenantId() != 0) {
            whStr.append(" and parent_id=:parent_id");
            paramts.put("parent_id", param.getTenantId());
        }
        if (StringUtils.isNotEmpty(param.getName())) {
            whStr.append(" and name like:name");
            paramts.put("name", "%" + param.getName() + "%");
        }
        if (StringUtils.isNotEmpty(param.getCode())) {
            whStr.append(" and code=:code");
            paramts.put("code", param.getCode());
        }
        whStr.append(" order by code ASC ");
        pager = this.finSysTenantService.selectSplit(new FinSysTenant(), whStr.toString(), paramts);
        return ResponseValue.success(pager);
    }
 
    /**
     * @Author :power
     * @Date : 2023/7/20 10:58 查询项目配置中 参与范围 (省/地市;地市) 该方法应是全局可见
     */
    @GetMapping("/project/selectTreeServingByProject")
    public ResponseValue selectTreeServingByProject() {
        // 省进入 查询 省和地市 ;地市进入 查询自己地市
        // TODO Long.valueOf(getSysInfo().getTenantId())
        FinSysTenant finSysTenant =
                this.finSysTenantService.get(new FinSysTenant(Long.valueOf(getSysInfo().getTenantId())));
        if (finSysTenant.getLv() == 3) {
            return ResponseValue.error("县区级别无法查看");
        }
        List<FinSysTenant> finSysTenantList =
                this.finSysTenantService.queryTreeById(finSysTenant.getId(), finSysTenant.getLv());
        List<TreeNode> treeNodeList = new ArrayList<>();
        // 省查本身及以下 市查本级 县无权查看
        if (finSysTenant.getLv() == 1) {
            treeNodeList = FinSysTenantUtils.getFinSysTenantTree(finSysTenantList);
            if (StringUtils.isEmptyList(treeNodeList)) {
                logger.error("未找到任何顶级区划树列表: treeNodeList = null");
            } else {
                logger.debug(treeNodeList.toString());
            }
        } else {
            TreeNode treeNode = new TreeNode(finSysTenantList.get(0).getId(), finSysTenantList.get(0).getName(),
                    new ArrayList<>(), finSysTenantList.get(0).getParentId(), finSysTenantList.get(0).getCode());
            treeNodeList.add(treeNode);
        }
        return ResponseValue.success(treeNodeList);
    }
 
    /**
     * @Author :power
     * @Date : 2023/7/20 16:33 项目配置 - 范围 - 查询县区 (省查询所有 地市查询自己管辖)
     */
    @GetMapping("/project/selectCounty")
    public ResponseValue selectCounty() {
        // 省进入 查询 省和地市 ;地市进入 查询自己地市
        // TODO Long.valueOf(getSysInfo().getTenantId())
        FinSysTenant finSysTenant =
                this.finSysTenantService.get(new FinSysTenant(Long.valueOf(getSysInfo().getTenantId())));
        if (finSysTenant.getLv() == 3) {
            return ResponseValue.error("县区级别无法查看");
        }
        Map<Long, List<FinSysTenant>> finSysTenantList =
                this.finSysTenantService.queryCountyByCityCode(finSysTenant.getId(), finSysTenant.getLv());
        return ResponseValue.success(finSysTenantList);
    }
 
    public void setEntityList(List<FinSysTenant> datas) {
 
        if (!StringUtils.isEmptyList(datas)) {
            TreeNode node = null;
            Iterator var3 = datas.iterator();
 
            while (var3.hasNext()) {
                Object obj = var3.next();
                node = this.toTreeNode((FinSysTenant) obj);
 
                if (node.getId() == this.defaultParentId) {
                    this.rootMap.put(node.getId(), node);
                } else if (node.getParentId() == this.defaultParentId) {
                    this.childMap.put(node.getId(), node);
                }
            }
 
            if (this.rootMap.size() == 0) {
                throw new IllegalArgumentException("未找到根节点。");
            } else {
                if (this.childMap != null && this.childMap.size() > 0) {
                    this.mountTree(this.childMap);
                }
 
                if (this.dummyRoot != null) {
                    var3 = this.rootMap.values().iterator();
 
                    while (var3.hasNext()) {
                        TreeNode n = (TreeNode) var3.next();
                        n.setParentId(this.defaultParentId);
                        this.dummyRoot.addChild(n);
                    }
                }
 
            }
        }
    }
 
    private void mountTree(Map<Long, TreeNode> childMap) {
        TreeNode _node = null;
        Iterator i = childMap.values().iterator();
 
        while (i.hasNext()) {
            _node = (TreeNode) i.next();
            this.mountMiddleNode(_node, childMap);
        }
 
    }
 
    private void mountMiddleNode(TreeNode currentNode, Map<Long, TreeNode> childMap) {
        TreeNode _parentNode = (TreeNode) this.rootMap.get(currentNode.getParentId());
        if (_parentNode == null) {
            _parentNode = (TreeNode) childMap.get(currentNode.getId());
            if (_parentNode == null) {
                throw new NullPointerException("parent node not found, current: " + currentNode);
            }
 
            _parentNode.addChild(currentNode);
            this.mountMiddleNode(_parentNode, childMap);
        } else if (_parentNode.getId() == this.defaultParentId) {
            _parentNode.addChild(currentNode);
        }
 
    }
 
    protected TreeNode toTreeNode(FinSysTenant entity) {
        TreeNode treeNode =
                new TreeNode(entity.getId(), entity.getName(), (List) null, entity.getParentId(), entity.getCode());
        return treeNode;
    }
 
    public List<TreeNode> getTreeRootList() {
        if (!this.multiRoot) {
            throw new IllegalStateException("存在多个根节点,请调用方法:getTreeRoot().");
        } else {
            List<TreeNode> list = new ArrayList();
            Iterator var2 = this.rootMap.values().iterator();
 
            while (var2.hasNext()) {
                TreeNode node = (TreeNode) var2.next();
                list.add(node);
            }
            return list;
        }
    }
 
    /**
     * @Description 不分页查询
     */
    @RequestMapping("/select/allList")
    public ResponseValue allList() {
        FinSysTenantSearchParam param = CommonUtil.getObjFromReq(FinSysTenantSearchParam.class);
        FinSysTenantSearchParam param2 = new FinSysTenantSearchParam();
        CommonUtil.copyProperties(param, param2);
        param = param2;
 
        StringBuilder whStr = new StringBuilder("where 1=1 and status = 1 and is_delete = 0 ");
        HashMap parameter = new HashMap<>();
        if (StringUtils.isNotEmpty(param.getFirstZmS())) {
            whStr.append(" and name is not null and(");
            String upperCase = param.getFirstZmS().toUpperCase();
            whStr.append(
                    "instr(:upperFirstZmS,F_PINYIN( SUBSTR(name, 1, 1)))>0 or instr(:upperFirstZmS2,SUBSTR(name, 1, 1))>0");
            parameter.put("upperFirstZmS", upperCase);
            parameter.put("upperFirstZmS2", upperCase);
            whStr.append(")");
        }
        whStr.append(" order by lv asc, F_PINYIN( SUBSTR(name, 1, 1)) ASC ");
        List<FinSysTenant> select = this.finSysTenantService.select(new FinSysTenant(), whStr.toString(), parameter);
        return ResponseValue.success(select);
    }
 
    /**
     * 删除
     *
     * @author 卢庆阳
     * @date 2023/10/4
     */
    @PostMapping("/del")
    public ResponseValue del() {
        FinSysTenantParam param = CommonUtil.getObjFromReqBody(FinSysTenantParam.class);
        FinSysTenantParam finSysTenantParam = new FinSysTenantParam();
        CommonUtil.copyProperties(param, finSysTenantParam);
        param = finSysTenantParam;
 
        if (param.getId() == null) {
            return ResponseValue.error("机构id为空");
        }
        int num = this.finSysTenantService.updateById(param, this.getSysInfo());
        return num > 0 ? ResponseValue.success(1) : ResponseValue.error("删除失败!");
    }
 
    /**
     * 添加机构
     *
     * @author 卢庆阳
     * @date 2023/10/4
     */
    @PostMapping("/add")
    public ResponseValue add() {
        FinSysTenantParam param = CommonUtil.getObjFromReqBody(FinSysTenantParam.class);
        FinSysTenantParam finSysTenantParam = new FinSysTenantParam();
        CommonUtil.copyProperties(param, finSysTenantParam);
        param = finSysTenantParam;
 
        if (param == null) {
            return ResponseValue.error("参数为空");
        }
        if (StringUtils.isEmpty(param.getCode())) {
            return ResponseValue.error("机构编号为空");
        }
        if (StringUtils.isEmpty(param.getName())) {
            return ResponseValue.error("机构名称为空");
        }
        FinSysTenant finSysTenant = this.finSysTenantService.queryOneByCode(param.getCode());
        if (finSysTenant != null) {
            return ResponseValue.error("机构编号已存在");
        }
        String parentIdStr = param.getParentId() + "";
        int lv = parentIdStr.length() / 3 + 1;
        if (lv > 4) {
            return ResponseValue.error("不能创建支局以下机构");
        }
        int num = this.finSysTenantService.addFinSysTenant(param, this.getSysInfo(), lv);
        if (num > 0) {
            return ResponseValue.success(1);
        }
        return ResponseValue.error("插入失败!");
    }
 
    @GetMapping("getImportTemplate")
    public ResponseEntity<InputStreamResource> getImportTemplate(String type) throws IOException {
        // 从当前项目资源目录获取文件
        String fileName = null;
        if ("tenant".equals(type)) {
            fileName = "机构导入模板.xls";
        } else if ("goods".equals(type)) {
            fileName = "物品信息.xls";
        } else if ("procure".equals(type)) {
            fileName = "采购导入.xls";
        } else if ("distribute".equals(type)) {
            fileName = "分发导入.xls";
        } else if ("classification".equals(type)) {
            fileName = "物品分类.xls";
        }
        Resource resource = new ClassPathResource("import/" + fileName);
        // 获取文件输入流
        InputStream inputStream = resource.getInputStream();
        // 设置HTTP响应头
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
        String encodedFilename = URLEncoder.encode(fileName, "UTF-8");
        headers.setContentDispositionFormData("attachment", encodedFilename);
        // 创建InputStreamResource对象,将文件输入流包装起来
        InputStreamResource resourceToDownload = new InputStreamResource(inputStream);
        // 返回带有文件输入流的ResponseEntity对象
        return ResponseEntity.status(HttpStatus.OK).headers(headers).body(resourceToDownload);
    }
 
    @PostMapping("import")
    public ResponseValue upload(@RequestParam Long pid, MultipartFile file) throws IOException {
        String originalFilename = file.getOriginalFilename();
        if (!originalFilename.endsWith("xls")) {
            return ResponseValue.error("文件格式有误!");
        }
        FinSysTenantUser sysInfo = this.getSysInfo();
        if (sysInfo == null) {
            return ResponseValue.error("当前登录用户为空");
        }
        String parentIdStr = pid + "";
        int lv = parentIdStr.length() / 3 + 1;
        if (lv > 3) {
            return ResponseValue.error("不能创建县(区)级以下机构");
        }
 
        EasyExcelFactory
                .read(file.getInputStream(), ImportTenantTemplate.class, new AnalysisEventListener<ImportTenantTemplate>() {
                    LinkedList<FinSysTenantParam> finSysTenantParams = new LinkedList<>();
 
                    @Override
                    public void invoke(ImportTenantTemplate finSysTenantParam, AnalysisContext analysisContext) {
                        String code = finSysTenantParam.getCode();
                        String tenantName = finSysTenantParam.getTenantName();
                        ReadSheetHolder readSheetHolder = analysisContext.readSheetHolder();
                        Integer rowIndex = readSheetHolder.getRowIndex() + 1;
                        if (StringUtils.isEmpty(code) || code.length() > 20) {
                            IllegalStateException exception =
                                    new IllegalStateException("第" + rowIndex + "行,机构编号不能为空或长度大于20");
                            throw exception;
                        }
                        if (null != finSysTenantService.queryOneByCode(code)) {
                            throw new IllegalStateException("第" + rowIndex + "行,机构编号已存在");
                        }
                        if (StringUtils.isEmpty(tenantName) || tenantName.length() > 100) {
                            IllegalStateException exception =
                                    new IllegalStateException("第" + rowIndex + "行,机构名称不能为空或长度大于100");
                            throw exception;
                        }
                        FinSysTenantParam tenantParam = new FinSysTenantParam();
                        tenantParam.setParentId(pid);
                        tenantParam.setStatus(1);
                        tenantParam.setSummary("系统导入");
                        tenantParam.setCode(code);
                        tenantParam.setName(tenantName);
                        finSysTenantParams.add(tenantParam);
                    }
 
                    @Override
                    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
                        finSysTenantService.insertFinSysTenantBatch(finSysTenantParams, sysInfo, lv);
                    }
 
                    @Override
                    public void onException(Exception exception, AnalysisContext context) {
                        // 如果是某一个单元格的转换异常 能获取到具体行号
                        if (exception instanceof ExcelDataConvertException) {
                            ExcelDataConvertException excelDataConvertException = (ExcelDataConvertException) exception;
                            Integer rowIndex = excelDataConvertException.getRowIndex() + 1;
                            Integer columnIndex = excelDataConvertException.getColumnIndex();
                            String stringValue = excelDataConvertException.getCellData().getStringValue();
                            logger.error("第{}行,第{}列解析异常,数据为:{}", rowIndex, columnIndex, stringValue);
                            throw new IllegalStateException(
                                    "第" + rowIndex + "行,第" + columnIndex + "列解析异常,异常数据为:[ " + stringValue + " ]");
                        }
                        if (exception instanceof IllegalStateException) {
                            throw (IllegalStateException) exception;
                        }
 
                    }
 
                }).doReadAll();
 
        return ResponseValue.success("导入成功!", 1);
    }
 
    /**
     * 编辑
     *
     * @author 卢庆阳
     * @date 2023/10/6
     */
    @PostMapping("/edit")
    public ResponseValue edit() {
        FinSysTenant param = CommonUtil.getObjFromReqBody(FinSysTenant.class);
        FinSysTenant finSysTenant = new FinSysTenant();
        CommonUtil.copyProperties(param, finSysTenant);
        param = finSysTenant;
 
        Long id = param.getId();
        if (id == null || id.longValue() <= 0) {
            return ResponseValue.error("编辑的机构不存在");
        }
        FinSysTenantUser sysInfo = getSysInfo();
        if (sysInfo == null) {
            return ResponseValue.error("登录用户信息不存在");
        }
 
        int num = this.finSysTenantService.updateFinSysTenant(param, this.getSysInfo());
        return num > 0 ? ResponseValue.success(1) : ResponseValue.error("编辑失败!");
    }
 
    /**
     * 修改启用禁用状态
     *
     * @return
     */
    @PostMapping("/editState")
    public ResponseValue editState() {
        FinSysTenant param = CommonUtil.getObjFromReqBody(FinSysTenant.class);
        FinSysTenant selFinSysTenant = finSysTenantService.selectById(param.getId());
        selFinSysTenant.setStatus(param.getStatus());
        //FinSysTenant finSysTenant = new FinSysTenant();
        param = selFinSysTenant;
        Long id = param.getId();
        if (id == null || id.longValue() <= 0) {
            return ResponseValue.error("编辑的机构不存在");
        }
        FinSysTenantUser sysInfo = getSysInfo();
        if (sysInfo == null) {
            return ResponseValue.error("登录用户信息不存在");
        }
        int num = this.finSysTenantService.updateFinSysTenant(param, this.getSysInfo());
        return num > 0 ? ResponseValue.success(1) : ResponseValue.error("编辑失败!");
    }
 
    /**
     * @Description 根据OrgCode获取上级及本级人员ID。可能是省市县
     * @Author wh
     * @Date 2023/10/4 15:37
     */
    @GetMapping("getUserByOrgId")
    public ResponseValue getUserByOrgCode(Long orgId) {
        if (orgId == null) {
            return ResponseValue.error("机构不能为空");
        }
        ArrayList<FinSysTenantUserResult> finSysTenantUserResults = new ArrayList<>();
        // 本级
        FinSysTenant finSysTenant = this.finSysTenantService.get(new FinSysTenant(orgId));
        if (finSysTenant.getLv() == 1) {
            // 省
            List<FinSysTenantUser> finSysTenantUserList = this.finSysTenantUserService.getByOrgId(orgId);
            if (!StringUtils.isEmptyList(finSysTenantUserList)) {
                FinSysTenantUserResult finSysTenantUserResult = new FinSysTenantUserResult();
                finSysTenantUserResult.setOrgId(finSysTenant.getId());
                finSysTenantUserResult.setOrgName(finSysTenant.getName());
                finSysTenantUserResult.setUserList(finSysTenantUserList);
                finSysTenantUserResults.add(finSysTenantUserResult);
            }
        }
        if (finSysTenant.getLv() == 2) {
            // 市
            List<FinSysTenantUser> finSysTenantUserList2 = this.finSysTenantUserService.getByOrgId(orgId);
            if (!StringUtils.isEmptyList(finSysTenantUserList2)) {
                FinSysTenantUserResult finSysTenantUserResult = new FinSysTenantUserResult();
                finSysTenantUserResult.setOrgId(finSysTenant.getId());
                finSysTenantUserResult.setOrgName(finSysTenant.getName());
                finSysTenantUserResult.setUserList(finSysTenantUserList2);
                finSysTenantUserResults.add(finSysTenantUserResult);
            }
            // 省
            FinSysTenant finSysTenant1 = this.finSysTenantService.get(new FinSysTenant(finSysTenant.getParentId()));
            List<FinSysTenantUser> finSysTenantUserList =
                    this.finSysTenantUserService.getByOrgId(finSysTenant1.getId());
            if (!StringUtils.isEmptyList(finSysTenantUserList)) {
                FinSysTenantUserResult finSysTenantUserResult = new FinSysTenantUserResult();
                finSysTenantUserResult.setOrgId(finSysTenant1.getId());
                finSysTenantUserResult.setOrgName(finSysTenant1.getName());
                finSysTenantUserResult.setUserList(finSysTenantUserList);
                finSysTenantUserResults.add(finSysTenantUserResult);
            }
        }
        if (finSysTenant.getLv() == 3) {
            // 县
            List<FinSysTenantUser> finSysTenantUserList3 = this.finSysTenantUserService.getByOrgId(orgId);
            if (!StringUtils.isEmptyList(finSysTenantUserList3)) {
                FinSysTenantUserResult finSysTenantUserResult = new FinSysTenantUserResult();
                finSysTenantUserResult.setOrgId(finSysTenant.getId());
                finSysTenantUserResult.setOrgName(finSysTenant.getName());
                finSysTenantUserResult.setUserList(finSysTenantUserList3);
                finSysTenantUserResults.add(finSysTenantUserResult);
            }
            // 市
            FinSysTenant finSysTenant2 = this.finSysTenantService.get(new FinSysTenant(finSysTenant.getParentId()));
            List<FinSysTenantUser> finSysTenantUserList2 =
                    this.finSysTenantUserService.getByOrgId(finSysTenant2.getId());
            if (!StringUtils.isEmptyList(finSysTenantUserList2)) {
                FinSysTenantUserResult finSysTenantUserResult = new FinSysTenantUserResult();
                finSysTenantUserResult.setOrgId(finSysTenant2.getId());
                finSysTenantUserResult.setOrgName(finSysTenant2.getName());
                finSysTenantUserResult.setUserList(finSysTenantUserList2);
                finSysTenantUserResults.add(finSysTenantUserResult);
            }
            // 省
            FinSysTenant finSysTenant1 = this.finSysTenantService.get(new FinSysTenant(finSysTenant2.getParentId()));
            List<FinSysTenantUser> finSysTenantUserList =
                    this.finSysTenantUserService.getByOrgId(finSysTenant1.getId());
            if (!StringUtils.isEmptyList(finSysTenantUserList)) {
                FinSysTenantUserResult finSysTenantUserResult = new FinSysTenantUserResult();
                finSysTenantUserResult.setOrgId(finSysTenant1.getId());
                finSysTenantUserResult.setOrgName(finSysTenant1.getName());
                finSysTenantUserResult.setUserList(finSysTenantUserList);
                finSysTenantUserResults.add(finSysTenantUserResult);
            }
        }
        return ResponseValue.success(finSysTenantUserResults);
    }
 
    @ApiOperation(value = "获取父级机构", notes = "获取父级机构")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "token", dataType = "String", paramType = "header"),})
    @GetMapping("/get/parent/tenant")
    public ResponseValue getParentTenant() {
        FinSysTenantUser sysInfo = getSysInfo();
        if (sysInfo == null) {
            return ResponseValue.error("登录用户信息不存在");
        }
        String tenantId = sysInfo.getTenantId();
        FinSysTenant userTenant = finSysTenantService.selectById(Long.valueOf(tenantId));
        Long parentId = userTenant.getParentId();
        // 第一级
        if (parentId == 0) {
            return ResponseValue.success(userTenant);
        } else {
            FinSysTenant result = finSysTenantService.selectById(parentId);
            return ResponseValue.success(result);
        }
    }
}