|  |  | 
 |  |  | import com.doumee.core.model.PageWrap; | 
 |  |  | import com.doumee.core.utils.Constants; | 
 |  |  | import com.doumee.core.utils.Utils; | 
 |  |  | import com.doumee.dao.business.CategoryMapper; | 
 |  |  | import com.doumee.dao.business.model.Category; | 
 |  |  | import com.doumee.dao.business.*; | 
 |  |  | import com.doumee.dao.business.dao.CompanyMapper; | 
 |  |  | import com.doumee.dao.business.model.*; | 
 |  |  | import com.doumee.service.business.CategoryService; | 
 |  |  | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
 |  |  | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; | 
 |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private CategoryMapper categoryMapper; | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private YwCustomerMapper ywCustomerMapper; | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private YwWorkorderMapper ywWorkorderMapper; | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private YwPatrolPointMapper ywPatrolPointMapper; | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private YwDeviceMapper ywDeviceMapper; | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private YwMaterialMapper ywMaterialMapper; | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     public Integer create(Category category) { | 
 |  |  |         checkUnique(category); | 
 |  |  | 
 |  |  |         return insert.getId(); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     public void deleteById(Integer id) { | 
 |  |  |         Category category = categoryMapper.selectById(id); | 
 |  |  |         if(Objects.isNull(category)){ | 
 |  |  |             throw new BusinessException(ResponseStatus.DATA_EMPTY); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         if(categoryMapper.selectCount(new QueryWrapper<Category>().lambda() | 
 |  |  |                 .eq(Category::getIsdeleted,Constants.ZERO) | 
 |  |  |                 .eq(Category::getParentId,id) | 
 |  |  |         )>Constants.ZERO){ | 
 |  |  |             throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"存在子集数据,无法进行删除"); | 
 |  |  |         } | 
 |  |  |         //查询数据是否已使用     3运维-工单分类 4运维-巡检区域 5运维-设备分类 6=客户行业 7=资产分类 | 
 |  |  |         if(Constants.equalsInteger(category.getType(),Constants.THREE)){ | 
 |  |  |             if(ywWorkorderMapper.selectCount(new QueryWrapper<YwWorkorder>().lambda().eq(YwWorkorder::getIsdeleted,Constants.ZERO).eq(YwWorkorder::getCateId,id))>Constants.ZERO)  throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"分类已被使用,无法进行删除"); | 
 |  |  |         }else if (Constants.equalsInteger(category.getType(),Constants.FOUR)){ | 
 |  |  |             if(ywPatrolPointMapper.selectCount(new QueryWrapper<YwPatrolPoint>().lambda().eq(YwPatrolPoint::getIsdeleted,Constants.ZERO).eq(YwPatrolPoint::getAreaId,id))>Constants.ZERO)  throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"分类已被使用,无法进行删除"); | 
 |  |  |         }else if (Constants.equalsInteger(category.getType(),Constants.FIVE)){ | 
 |  |  |             if(ywDeviceMapper.selectCount(new QueryWrapper<YwDevice>().lambda().eq(YwDevice::getIsdeleted,Constants.ZERO).eq(YwDevice::getCateId,id))>Constants.ZERO)  throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"分类已被使用,无法进行删除"); | 
 |  |  |         }else if (Constants.equalsInteger(category.getType(),Constants.SIX)){ | 
 |  |  |             if(ywCustomerMapper.selectCount(new QueryWrapper<YwCustomer>().lambda().eq(YwCustomer::getIsdeleted,Constants.ZERO).eq(YwCustomer::getIndustryId,id))>Constants.ZERO)  throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"分类已被使用,无法进行删除"); | 
 |  |  |         }else if (Constants.equalsInteger(category.getType(),Constants.SEVEN)){ | 
 |  |  |             if(ywMaterialMapper.selectCount(new QueryWrapper<YwMaterial>().lambda().eq(YwMaterial::getIsdeleted,Constants.ZERO).eq(YwMaterial::getCateId,id))>Constants.ZERO)  throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"分类已被使用,无法进行删除"); | 
 |  |  |         } | 
 |  |  |         categoryMapper.update(null,new UpdateWrapper<Category>().lambda().set(Category::getIsdeleted,Constants.ONE) | 
 |  |  |                 .eq(Category::getId,id) | 
 |  |  |         ); | 
 |  |  | 
 |  |  |         Utils.MP.blankToNull(pageWrap.getModel()); | 
 |  |  |         queryWrapper.lambda().eq(Category::getIsdeleted,Constants.ZERO) | 
 |  |  |                 .eq(Objects.nonNull(pageWrap.getModel().getType()),Category::getType,pageWrap.getModel().getType()) | 
 |  |  |                 .isNull(Category::getParentId); | 
 |  |  |                 .isNull(Category::getParentId) | 
 |  |  |                 .orderByAsc(Category::getSortnum) | 
 |  |  |         ; | 
 |  |  |         PageData<Category> categoryPageData = PageData.from(categoryMapper.selectPage(page, queryWrapper)); | 
 |  |  |         //查询所有二级数据 | 
 |  |  |         List<Category> categoryList = categoryMapper.selectList( | 
 |  |  | 
 |  |  |     private void checkUnique(Category category){ | 
 |  |  |         QueryWrapper<Category> wrapper = new QueryWrapper<>(); | 
 |  |  |         wrapper.lambda() | 
 |  |  |                 .eq(Objects.nonNull(category.getId()),Category::getId,category.getId()) | 
 |  |  |                 .ne(Objects.nonNull(category.getId()),Category::getId,category.getId()) | 
 |  |  |                 .eq(Category::getIsdeleted,Constants.ZERO) | 
 |  |  |                 .eq(Objects.nonNull(category.getParentId()),Category::getParentId,category.getParentId()) | 
 |  |  |                 .isNull(Objects.isNull(category.getParentId()),Category::getParentId) | 
 |  |  |                 .eq(Category::getType,category.getType()) | 
 |  |  |                 .eq(Category::getName,category.getName()); | 
 |  |  |  |