| | |
| | | package com.consum.base.controller; |
| | | |
| | | import com.alibaba.excel.EasyExcel; |
| | | import com.alibaba.excel.context.AnalysisContext; |
| | | import com.alibaba.excel.event.AnalysisEventListener; |
| | | import com.alibaba.excel.exception.ExcelDataConvertException; |
| | | import com.consum.base.BaseController; |
| | | 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.util.FinSysTenantUtils; |
| | | 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 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.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.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.*; |
| | | 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 区划 |
| | | * @Description 机构 |
| | | * @Author wh |
| | | * @Date 2023/7/13 19:51 |
| | | */ |
| | | @Api(value = "机构管理", tags = "机构管理") |
| | | @RestController |
| | | @RequestMapping("/pc/fin/sys/tenant") |
| | | public class FinSysTenantController extends BaseController { |
| | | |
| | | private FinSysTenantServiceImpl finSysTenantService; |
| | | private FinSysTenantService finSysTenantService; |
| | | |
| | | @Autowired |
| | | private FinSysTenantUserServiceImpl finSysTenantUserService; |
| | | private FinSysTenantUserService finSysTenantUserService; |
| | | |
| | | @Autowired |
| | | public FinSysTenantController(FinSysTenantServiceImpl finSysTenantService) { |
| | | public FinSysTenantController(FinSysTenantService finSysTenantService) { |
| | | this.finSysTenantService = finSysTenantService; |
| | | } |
| | | |
| | |
| | | private long defaultParentId = 0L; |
| | | |
| | | /** |
| | | * @Description 获取区划树 |
| | | * @Description 获取机构树 |
| | | * @Author wh |
| | | * @Date 2023/7/11 11:15 |
| | | */ |
| | | @GetMapping("/select/tree_fin_tenant") |
| | | public ResponseValue listOrgRootTree() { |
| | | List<FinSysTenant> finSysTenantList = null; |
| | | FinSysTenantUser finSysTenantUser = new FinSysTenantUser(); |
| | | finSysTenantUser.setSysUserId(this.getCurrentUser().getId()); |
| | | List<FinSysTenantUser> finSysTenantUserList = finSysTenantUserService.select(finSysTenantUser); |
| | | FinSysTenantUser user = null; // 系统用户 |
| | | FinSysTenant finSysTenant1 = null; |
| | | List<TreeNode> treeRootList = null; // 数列表 |
| | | FinSysTenant finSysTenant = new FinSysTenant(); |
| | | // 获取地区父级 |
| | | finSysTenantList = this.finSysTenantService.queryForTree(); |
| | | // 根据登陆人id获取系统用户,如果有系统用户时 |
| | | if (finSysTenantUserList.size() > 0) { |
| | | // 获取当前用户信息 |
| | | user = finSysTenantUserList.get(0); |
| | | String tenantId = user.getTenantId(); |
| | | finSysTenant.setId(new Long(tenantId)); |
| | | // 查询区域 |
| | | List<FinSysTenant> select = finSysTenantService.select(finSysTenant); |
| | | if (select.size() > 0) { |
| | | finSysTenant1 = select.get(0); |
| | | } |
| | | // 系统用户 |
| | | FinSysTenantUser user = this.getSysInfo(); |
| | | if (Objects.isNull(user)) { |
| | | return ResponseValue.error("登录用户信息不存在"); |
| | | } |
| | | if (finSysTenant1 != null) { |
| | | if (finSysTenant1.getLv() != 1 && finSysTenant1.getParentId() != 0 && user != null) { |
| | | |
| | | // 获取所有机构 |
| | | 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()); |
| | |
| | | * @Date 2023/7/14 13:59 |
| | | */ |
| | | @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("登录用户信息不存在"); |
| | |
| | | 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()); |
| | | } |
| | |
| | | // 省进入 查询 省和地市 ;地市进入 查询自己地市 |
| | | // TODO Long.valueOf(getSysInfo().getTenantId()) |
| | | FinSysTenant finSysTenant = |
| | | this.finSysTenantService.get(new FinSysTenant(Long.valueOf(getSysInfo().getTenantId()))); |
| | | 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()); |
| | | this.finSysTenantService.queryTreeById(finSysTenant.getId(), finSysTenant.getLv()); |
| | | List<TreeNode> treeNodeList = new ArrayList<>(); |
| | | // 省查本身及以下 市查本级 县无权查看 |
| | | if (finSysTenant.getLv() == 1) { |
| | |
| | | } |
| | | } else { |
| | | TreeNode treeNode = new TreeNode(finSysTenantList.get(0).getId(), finSysTenantList.get(0).getName(), |
| | | new ArrayList<>(), finSysTenantList.get(0).getParentId(), finSysTenantList.get(0).getCode()); |
| | | new ArrayList<>(), finSysTenantList.get(0).getParentId(), finSysTenantList.get(0).getCode()); |
| | | treeNodeList.add(treeNode); |
| | | } |
| | | return ResponseValue.success(treeNodeList); |
| | |
| | | // 省进入 查询 省和地市 ;地市进入 查询自己地市 |
| | | // TODO Long.valueOf(getSysInfo().getTenantId()) |
| | | FinSysTenant finSysTenant = |
| | | this.finSysTenantService.get(new FinSysTenant(Long.valueOf(getSysInfo().getTenantId()))); |
| | | 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()); |
| | | this.finSysTenantService.queryCountyByCityCode(finSysTenant.getId(), finSysTenant.getLv()); |
| | | return ResponseValue.success(finSysTenantList); |
| | | } |
| | | |
| | |
| | | |
| | | while (var3.hasNext()) { |
| | | Object obj = var3.next(); |
| | | node = this.toTreeNode((FinSysTenant) obj); |
| | | node = this.toTreeNode((FinSysTenant)obj); |
| | | |
| | | if (node.getId() == this.defaultParentId) { |
| | | this.rootMap.put(node.getId(), node); |
| | |
| | | var3 = this.rootMap.values().iterator(); |
| | | |
| | | while (var3.hasNext()) { |
| | | TreeNode n = (TreeNode) var3.next(); |
| | | TreeNode n = (TreeNode)var3.next(); |
| | | n.setParentId(this.defaultParentId); |
| | | this.dummyRoot.addChild(n); |
| | | } |
| | |
| | | Iterator i = childMap.values().iterator(); |
| | | |
| | | while (i.hasNext()) { |
| | | _node = (TreeNode) i.next(); |
| | | _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()); |
| | | TreeNode _parentNode = (TreeNode)this.rootMap.get(currentNode.getParentId()); |
| | | if (_parentNode == null) { |
| | | _parentNode = (TreeNode) childMap.get(currentNode.getId()); |
| | | _parentNode = (TreeNode)childMap.get(currentNode.getId()); |
| | | if (_parentNode == null) { |
| | | throw new NullPointerException("parent node not found, current: " + currentNode); |
| | | } |
| | |
| | | |
| | | protected TreeNode toTreeNode(FinSysTenant entity) { |
| | | TreeNode treeNode = |
| | | new TreeNode(entity.getId(), entity.getName(), (List) null, entity.getParentId(), entity.getCode()); |
| | | new TreeNode(entity.getId(), entity.getName(), (List)null, entity.getParentId(), entity.getCode()); |
| | | return treeNode; |
| | | } |
| | | |
| | |
| | | Iterator var2 = this.rootMap.values().iterator(); |
| | | |
| | | while (var2.hasNext()) { |
| | | TreeNode node = (TreeNode) var2.next(); |
| | | TreeNode node = (TreeNode)var2.next(); |
| | | list.add(node); |
| | | } |
| | | return list; |
| | |
| | | * @Description 不分页查询 |
| | | */ |
| | | @RequestMapping("/select/allList") |
| | | public ResponseValue allList(FinSysTenantSearchParam param) { |
| | | 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 (param.getFirstZmS() != null && !param.getFirstZmS().equals("")) { |
| | | 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"); |
| | | 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(")"); |
| | |
| | | return ResponseValue.success(select); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 删除 |
| | | * |
| | | * @author 卢庆阳 |
| | | * @date 2023/10/4 |
| | | */ |
| | | @PostMapping("/del") |
| | | public ResponseValue del(@RequestBody FinSysTenantParam param) { |
| | | 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("删除失败!"); |
| | | 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(@RequestBody FinSysTenantParam param){ |
| | | 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.getName())) { |
| | | return ResponseValue.error("机构名称为空"); |
| | | } |
| | | FinSysTenant finSysTenant = this.finSysTenantService.selectByTenantId(param.getCode()); |
| | | FinSysTenant finSysTenant = this.finSysTenantService.queryOneByCode(param.getCode()); |
| | | if (finSysTenant != null) { |
| | | return ResponseValue.error("机构编号已存在"); |
| | | } |
| | |
| | | if (lv > 4) { |
| | | return ResponseValue.error("不能创建支局以下机构"); |
| | | } |
| | | int num = this.finSysTenantService.addFinSysTenant(param,this.getSysInfo(),lv); |
| | | if(num>0) return ResponseValue.success(1); |
| | | 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() throws IOException { |
| | | public ResponseEntity<InputStreamResource> getImportTemplate(String type) throws IOException { |
| | | // 从当前项目资源目录获取文件 |
| | | Resource resource = new ClassPathResource("import/机构导入模板.xls"); |
| | | String fileName = null; |
| | | if ("tenant".equals(type)) { |
| | | fileName = "机构导入模板.xls"; |
| | | } else if ("goods".equals(type)) { |
| | | fileName = "物品信息.xls"; |
| | | } else if ("procure".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("机构导入模板.xls", "UTF-8"); |
| | | 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); |
| | | return ResponseEntity.status(HttpStatus.OK).headers(headers).body(resourceToDownload); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * @return 获取项目导入的模板 |
| | | * @throws IOException |
| | | */ |
| | | @GetMapping("getProjectImportTemplate") |
| | | public ResponseEntity<InputStreamResource> getProjectImportTemplate() throws IOException { |
| | | // 从当前项目资源目录获取文件 |
| | | Resource resource = new ClassPathResource("import/项目导入模板.xls"); |
| | | // 获取文件输入流 |
| | | InputStream inputStream = resource.getInputStream(); |
| | | // 设置HTTP响应头 |
| | | HttpHeaders headers = new HttpHeaders(); |
| | | headers.setContentType(MediaType.APPLICATION_OCTET_STREAM); |
| | | String encodedFilename = URLEncoder.encode("项目导入模板.xls", "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 (!"xls".equals(originalFilename.substring(originalFilename.lastIndexOf(".") + 1))){ |
| | | if (!originalFilename.endsWith("xls")) { |
| | | return ResponseValue.error("文件格式有误!"); |
| | | } |
| | | FinSysTenantUser sysInfo = this.getSysInfo(); |
| | | if (sysInfo==null){ |
| | | if (sysInfo == null) { |
| | | return ResponseValue.error("当前登录用户为空"); |
| | | } |
| | | String parentIdStr = pid + ""; |
| | |
| | | return ResponseValue.error("不能创建县(区)级以下机构"); |
| | | } |
| | | |
| | | 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"); |
| | | 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"); |
| | | throw exception; |
| | | } |
| | | finSysTenantParam.setParentId(pid); |
| | | finSysTenantParam.setStatus(1); |
| | | finSysTenantParam.setSummary("系统导入"); |
| | | finSysTenantParams.add(finSysTenantParam); |
| | | } |
| | | @Override |
| | | public void doAfterAllAnalysed(AnalysisContext analysisContext) { |
| | | finSysTenantService.insertFinSysTenantBatch(finSysTenantParams,sysInfo,lv); |
| | | } |
| | | EasyExcelFactory |
| | | .read(file.getInputStream(), ImportTenantTemplate.class, new AnalysisEventListener<ImportTenantTemplate>() { |
| | | LinkedList<FinSysTenantParam> finSysTenantParams = new LinkedList<>(); |
| | | |
| | | @Override |
| | | public void onException(Exception exception, AnalysisContext context) { |
| | | // 如果是某一个单元格的转换异常 能获取到具体行号 |
| | | if (exception instanceof ExcelDataConvertException) { |
| | | 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()+" ]"); |
| | | } |
| | | if (exception instanceof IllegalStateException){ |
| | | throw (IllegalStateException)exception; |
| | | @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); |
| | | } |
| | | |
| | | }).doReadAll(); |
| | | @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; |
| | | } |
| | | |
| | | return ResponseValue.success("导入成功!",1); |
| | | } |
| | | |
| | | }).doReadAll(); |
| | | |
| | | return ResponseValue.success("导入成功!", 1); |
| | | } |
| | | |
| | | /** |
| | | * 编辑 |
| | | * |
| | | * @author 卢庆阳 |
| | | * @date 2023/10/6 |
| | | */ |
| | | @PostMapping("/edit") |
| | | public ResponseValue edit(@RequestBody FinSysTenant finSysTenant) { |
| | | Long id = finSysTenant.getId(); |
| | | 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("编辑的机构不存在"); |
| | | } |
| | |
| | | if (sysInfo == null) { |
| | | return ResponseValue.error("登录用户信息不存在"); |
| | | } |
| | | // FinSysTenant finSysTenant1 = this.finSysTenantService.selectByTenantId(sysInfo.getTenantCode()); |
| | | // if (finSysTenant1.getLv() != 1) { |
| | | // return ResponseValue.error("暂无修改权限"); |
| | | // } |
| | | int num = this.finSysTenantService.updateFinSysTenant(finSysTenant,this.getSysInfo()); |
| | | return num>0 ? ResponseValue.success(1):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("编辑失败!"); |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | // 省 |
| | | FinSysTenant finSysTenant1 = this.finSysTenantService.get(new FinSysTenant(finSysTenant.getParentId())); |
| | | List<FinSysTenantUser> finSysTenantUserList = this.finSysTenantUserService.getByOrgId(finSysTenant1.getId()); |
| | | List<FinSysTenantUser> finSysTenantUserList = |
| | | this.finSysTenantUserService.getByOrgId(finSysTenant1.getId()); |
| | | if (!StringUtils.isEmptyList(finSysTenantUserList)) { |
| | | FinSysTenantUserResult finSysTenantUserResult = new FinSysTenantUserResult(); |
| | | finSysTenantUserResult.setOrgId(finSysTenant1.getId()); |
| | |
| | | } |
| | | // 市 |
| | | FinSysTenant finSysTenant2 = this.finSysTenantService.get(new FinSysTenant(finSysTenant.getParentId())); |
| | | List<FinSysTenantUser> finSysTenantUserList2 = this.finSysTenantUserService.getByOrgId(finSysTenant2.getId()); |
| | | List<FinSysTenantUser> finSysTenantUserList2 = |
| | | this.finSysTenantUserService.getByOrgId(finSysTenant2.getId()); |
| | | if (!StringUtils.isEmptyList(finSysTenantUserList2)) { |
| | | FinSysTenantUserResult finSysTenantUserResult = new FinSysTenantUserResult(); |
| | | finSysTenantUserResult.setOrgId(finSysTenant2.getId()); |
| | |
| | | } |
| | | // 省 |
| | | FinSysTenant finSysTenant1 = this.finSysTenantService.get(new FinSysTenant(finSysTenant2.getParentId())); |
| | | List<FinSysTenantUser> finSysTenantUserList = this.finSysTenantUserService.getByOrgId(finSysTenant1.getId()); |
| | | List<FinSysTenantUser> finSysTenantUserList = |
| | | this.finSysTenantUserService.getByOrgId(finSysTenant1.getId()); |
| | | if (!StringUtils.isEmptyList(finSysTenantUserList)) { |
| | | FinSysTenantUserResult finSysTenantUserResult = new FinSysTenantUserResult(); |
| | | finSysTenantUserResult.setOrgId(finSysTenant1.getId()); |
| | |
| | | } |
| | | 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); |
| | | } |
| | | } |
| | | } |