consum-base/src/main/java/com/consum/base/controller/FinSysTenantController.java
@@ -1,74 +1,149 @@
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.service.FinSysTenantServiceImpl;
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 org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
/**
 * @Description 系统机构
 * @Author 卢庆阳
 * @Date 2023/10/23
 * @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 FinSysTenantServiceImpl finSysTenantService;
    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;
    /**
     * 添加机构
     * @author 卢庆阳
     * @date 2023/10/4
     * @Description 获取机构树
     * @Author wh
     * @Date 2023/7/11 11:15
     */
    @PostMapping("/add")
    public ResponseValue add(@RequestBody FinSysTenantParam param){
        if (param == null) {
            return ResponseValue.error("参数为空");
        }
        if (StringUtils.isEmpty(param.getCode())) {
            return ResponseValue.error("机构编号为空");
        }
        if (StringUtils.isEmpty(param.getName())) {
            return ResponseValue.error("机构名称为空");
        }
        if (param.getParentId() == null) {
            return ResponseValue.error("上级机构不存在");
        }
        //根据机构id查询机构
        FinSysTenant sysTenant = this.finSysTenantService.selectByTenantId(param.getCode());
        if (sysTenant != null) {
            return ResponseValue.error("机构编号已存在");
        }
        String parentIdStr = param.getParentId() + "";
        int lv = parentIdStr.length() / 3 + 1;
        if (lv > 4) {
            return ResponseValue.error("不能创建支局以下机构");
    @GetMapping("/select/tree_fin_tenant")
    public ResponseValue listOrgRootTree() {
        // 系统用户
        FinSysTenantUser user = this.getSysInfo();
        if (Objects.isNull(user)) {
            return ResponseValue.error("登录用户信息不存在");
        }
        int num = this.finSysTenantService.addSysTenant(param,this.getCurrentUser(),lv);
        if(num>0) return ResponseValue.success(1);
        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 卢庆阳
     * @Date 2023/10/24
     * @Description 分页列表查询
     * @Author llb
     * @Date 2023/7/14 13:59
     */
//    @RequestMapping("/select/list")
    @RequestMapping("/select/list")
    public ResponseValue allocatedList(FinSysTenantSearchParam param) {
    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("登录用户信息不存在");
@@ -90,11 +165,11 @@
            whStr.append(" and parent_id=:parent_id");
            paramts.put("parent_id", param.getTenantId());
        }
        if (param.getName() != null && !param.getName().equals("")) {
        if (StringUtils.isNotEmpty(param.getName())) {
            whStr.append(" and name like:name");
            paramts.put("name", "%" + param.getName() + "%");
        }
        if (param.getCode() != null && !param.getCode().equals("")) {
        if (StringUtils.isNotEmpty(param.getCode())) {
            whStr.append(" and code=:code");
            paramts.put("code", param.getCode());
        }
@@ -103,5 +178,481 @@
        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);
        }
    }
}