| | |
| | | package com.gkhy.exam.system.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.gkhy.exam.common.api.CommonPage; |
| | | import com.gkhy.exam.common.api.CommonResult; |
| | | import com.gkhy.exam.common.exception.ApiException; |
| | | import com.gkhy.exam.common.utils.SecurityUtils; |
| | | import com.gkhy.exam.system.domain.*; |
| | | import com.gkhy.exam.system.domain.req.CatalogueDataReq; |
| | |
| | | private List<CatalogueVo> getchildren(CatalogueVo catalogueVo, List<CatalogueVo> catalogueVos) { |
| | | List<CatalogueVo> catalogueCharlden = new ArrayList<>(); |
| | | for (CatalogueVo catalogue : catalogueVos) { |
| | | if (catalogueVo.getId() == catalogue.getParentId()){ |
| | | if (catalogueVo.getId().equals(catalogue.getParentId())){ |
| | | catalogueCharlden.add(catalogue); |
| | | } |
| | | } |
| | |
| | | |
| | | @Override |
| | | public CommonResult insertCatalogue(Catalogue catalogue) { |
| | | if (catalogue.getType()==2||catalogue.getType()==3){ |
| | | if (catalogue.getCompanyId()==null){ |
| | | throw new ApiException("企业id不能为空"); |
| | | } |
| | | } |
| | | catalogue.setCreateBy(SecurityUtils.getUsername()); |
| | | catalogue.setCreateTime(LocalDate.now()); |
| | | int insert = catalogueMapper.insert(catalogue); |
| | |
| | | public CommonResult selectCatalogueDataFileList(CatalogueReq catalogueReq) { |
| | | return CommonResult.success(catalogueMapper.selectCatalogueDataFile(catalogueReq.getCompanyId(),catalogueReq.getCatalogueId())); |
| | | } |
| | | |
| | | @Override |
| | | public CommonResult copyCatalogue(List<CatalogueVo> catalogue) { |
| | | Integer companyId = catalogue.get(0).getCompanyId(); |
| | | catalogueMapper.delete(Wrappers.<Catalogue>lambdaQuery().eq(Catalogue::getCompanyId,companyId)); |
| | | for (CatalogueVo catalogueVo : catalogue) { |
| | | Catalogue catalogue1 = new Catalogue(); |
| | | BeanUtils.copyProperties(catalogueVo,catalogue1); |
| | | catalogueMapper.insertCatalogue(catalogue1); |
| | | List<CatalogueVo> children = catalogueVo.getChildren(); |
| | | if (children.size()>0){ |
| | | saveCatalogue(children,catalogue1); |
| | | } |
| | | } |
| | | return CommonResult.success(); |
| | | } |
| | | |
| | | private void saveCatalogue(List<CatalogueVo> children,Catalogue catalogue) { |
| | | for (CatalogueVo child : children) { |
| | | Catalogue catalogue1 = new Catalogue(); |
| | | BeanUtils.copyProperties(child,catalogue1); |
| | | catalogue1.setParentId(catalogue.getId()); |
| | | catalogue1.setCompanyId(catalogue.getCompanyId()); |
| | | catalogueMapper.insertCatalogue(catalogue1); |
| | | List<CatalogueVo> children1 = child.getChildren(); |
| | | if (children1.size()>0){ |
| | | saveCatalogue(children1,catalogue1); |
| | | }else { |
| | | continue; |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | } |