futian.liu
2023-11-15 dc1800d4d2d252b7b37d80d9f54285200c94ff3c
consum-base/src/main/java/com/consum/base/controller/FinSysTenantController.java
@@ -5,11 +5,11 @@
import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.excel.exception.ExcelDataConvertException;
import com.consum.base.BaseController;
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.service.FinSysTenantUserServiceImpl;
import com.consum.base.core.utils.FinSysTenantUtils;
import com.consum.model.po.FinSysTenant;
import com.consum.model.po.FinSysTenantUser;
import com.consum.model.vo.FinSysTenantUserResult;
@@ -17,6 +17,19 @@
import com.walker.infrastructure.tree.TreeNode;
import com.walker.infrastructure.utils.StringUtils;
import com.walker.web.ResponseValue;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
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.TreeMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.ClassPathResource;
@@ -26,13 +39,13 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
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 java.io.IOException;
import java.io.InputStream;
import java.net.URLEncoder;
import java.util.*;
/**
 * @Description 区划
@@ -314,6 +327,7 @@
    /**
     * 删除
     *
     * @author 卢庆阳
     * @date 2023/10/4
     */
@@ -328,6 +342,7 @@
    /**
     * 添加机构
     *
     * @author 卢庆阳
     * @date 2023/10/4
     */
@@ -352,7 +367,9 @@
            return ResponseValue.error("不能创建支局以下机构");
        }
        int num = this.finSysTenantService.addFinSysTenant(param,this.getSysInfo(),lv);
        if(num>0) return ResponseValue.success(1);
        if (num > 0) {
            return ResponseValue.success(1);
        }
        return ResponseValue.error("插入失败!");
    }
@@ -420,17 +437,20 @@
        EasyExcel.read(file.getInputStream(), FinSysTenantParam.class, new AnalysisEventListener<FinSysTenantParam>() {
            LinkedList<FinSysTenantParam> finSysTenantParams = new LinkedList<>();
            @Override
            public void invoke(FinSysTenantParam finSysTenantParam, AnalysisContext analysisContext) {
                if (StringUtils.isEmpty(finSysTenantParam.getCode())||finSysTenantParam.getCode().length()>20){
                    IllegalStateException exception = new IllegalStateException("第" + analysisContext.readSheetHolder().getRowIndex() + "行,机构编号不能为空或长度大于20");
                    IllegalStateException exception = new IllegalStateException(
                        "第" + analysisContext.readSheetHolder().getRowIndex() + "行,机构编号不能为空或长度大于20");
                    throw exception;
                }
                if (null!=finSysTenantService.selectByTenantId(finSysTenantParam.getCode())){
                    throw new IllegalStateException("第" + analysisContext.readSheetHolder().getRowIndex() + "行,机构编号已存在");
                }
                if (StringUtils.isEmpty(finSysTenantParam.getName())||finSysTenantParam.getName().length()>100){
                    IllegalStateException exception = new IllegalStateException("第" + analysisContext.readSheetHolder().getRowIndex() + "行,机构名称不能为空或长度大于100");
                    IllegalStateException exception = new IllegalStateException(
                        "第" + analysisContext.readSheetHolder().getRowIndex() + "行,机构名称不能为空或长度大于100");
                    throw exception;
                }
                finSysTenantParam.setParentId(pid);
@@ -438,6 +458,7 @@
                finSysTenantParam.setSummary("系统导入");
                finSysTenantParams.add(finSysTenantParam);
            }
            @Override
            public void doAfterAllAnalysed(AnalysisContext analysisContext) {
                finSysTenantService.insertFinSysTenantBatch(finSysTenantParams,sysInfo,lv);
@@ -450,7 +471,9 @@
                    ExcelDataConvertException excelDataConvertException = (ExcelDataConvertException)exception;
                    logger.error("第{}行,第{}列解析异常,数据为:{}",excelDataConvertException.getRowIndex(),
                            excelDataConvertException.getColumnIndex()+1, excelDataConvertException.getCellData().getStringValue());
                    throw new IllegalStateException("第"+(excelDataConvertException.getRowIndex()+1)+"行,第"+(excelDataConvertException.getColumnIndex()+1)+"列解析异常,异常数据为:[ "+excelDataConvertException.getCellData().getStringValue()+" ]");
                    throw new IllegalStateException(
                        "第" + (excelDataConvertException.getRowIndex() + 1) + "行,第" + (excelDataConvertException.getColumnIndex() + 1) + "列解析异常,异常数据为:[ "
                            + excelDataConvertException.getCellData().getStringValue() + " ]");
                }
                if (exception instanceof IllegalStateException){
                    throw (IllegalStateException)exception;
@@ -465,6 +488,7 @@
    /**
     * 编辑
     *
     * @author 卢庆阳
     * @date 2023/10/6
     */
@@ -564,4 +588,30 @@
        }
        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 finSysTenant = new FinSysTenant();
        finSysTenant.setTempId(Long.valueOf(tenantId));
        FinSysTenant userTenant = this.finSysTenantService.get(finSysTenant);
        Long parentId = userTenant.getParentId();
        //第一级
        if (parentId == 0) {
            return ResponseValue.success(userTenant);
        } else {
            FinSysTenant param = new FinSysTenant();
            param.setTempId(Long.valueOf(parentId));
            FinSysTenant result = this.finSysTenantService.get(param);
            return ResponseValue.success(result);
        }
    }
}