| | |
| | | package com.doumee.service.business.impl; |
| | | |
| | | import com.doumee.core.constants.Constants; |
| | | import com.doumee.core.constants.Constants; |
| | | import com.doumee.core.constants.ResponseStatus; |
| | | import com.doumee.core.exception.BusinessException; |
| | | import com.doumee.core.model.LoginUserInfo; |
| | | import com.doumee.core.model.PageData; |
| | | import com.doumee.core.model.PageWrap; |
| | | import com.doumee.core.utils.Utils; |
| | | import com.doumee.dao.business.CategoryMapper; |
| | | import com.doumee.dao.business.model.Category; |
| | | import com.doumee.dao.business.model.Member; |
| | | import com.doumee.dao.business.vo.CompanyTree; |
| | | import com.doumee.dao.web.vo.CategoryVO; |
| | | import com.doumee.dao.web.vo.CategoryVOTree; |
| | | import com.doumee.dao.business.model.Company; |
| | | import com.doumee.dao.business.model.Managers; |
| | | import com.doumee.dao.business.vo.CategoryTree; |
| | | import com.doumee.dao.business.vo.CompanyTree; |
| | | import com.doumee.dao.system.model.SystemUser; |
| | | import com.doumee.service.business.CategoryService; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.github.yulichang.wrapper.MPJLambdaWrapper; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.apache.shiro.SecurityUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import java.util.UUID; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 分类信息表Service实现 |
| | |
| | | |
| | | @Override |
| | | public Integer create(Category category) { |
| | | if(StringUtils.isBlank(category.getName())){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST); |
| | | } |
| | | if(category.getType()==null){ |
| | | throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(), "对不起,组织类型不正确,请按要求填写~"); |
| | | } |
| | | /* //查询名称不能重复 |
| | | if(categoryMapper.selectCount(new QueryWrapper<Category>().lambda() |
| | | .eq(Category::getName,category.getName()) |
| | | .eq(Category::getIsdeleted,Constants.ZERO)) >0){ |
| | | throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(), "对不起,名称不能重复~"); |
| | | }*/ |
| | | LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); |
| | | category.setIdPath(category.getId()+"/");//名称路径 |
| | | category.setNamePath(category.getName());//名称路径 |
| | | String idPath = ""; |
| | | if(category.getParentId() !=null){ |
| | | Category parent = findById(category.getParentId()); |
| | | if(parent == null || Constants.equalsInteger(parent.getIsdeleted(),Constants.ONE)){ |
| | | throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(), "对不起,父级信息不存在~"); |
| | | } |
| | | if(Constants.equalsInteger(parent.getType(),Constants.FOUR) && parent.getParentId()!=null){ |
| | | //如果是二级CDA主题,自己为观察项 |
| | | category.setType(Constants.SIX); |
| | | } |
| | | idPath = parent.getIdPath(); |
| | | category.setIdPath(parent.getIdPath()+category.getId()+"/"); |
| | | category.setNamePath(parent.getNamePath()+"/"+category.getName()); |
| | | } |
| | | category.setCreateDate(new Date()); |
| | | category.setCreator(user.getId()); |
| | | category.setIsdeleted(Constants.ZERO); |
| | | category.setStatus(Constants.ZERO); |
| | | category.setEditDate(category.getCreateDate()); |
| | | category.setEditor(category.getCreator()); |
| | | categoryMapper.insert(category); |
| | | |
| | | Category com = new Category(); |
| | | com.setId(category.getId()); |
| | | com.setIdPath(idPath+category.getId()+"/"); |
| | | categoryMapper.updateById(com); |
| | | return category.getId(); |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void deleteById(Integer id) { |
| | | categoryMapper.deleteById(id); |
| | | Category model = new Category(); |
| | | model.setId(id); |
| | | LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); |
| | | model.setEditor(user.getId()); |
| | | model.setEditDate(new Date()); |
| | | model.setIsdeleted(Constants.ONE); |
| | | categoryMapper.updateById(model); |
| | | } |
| | | |
| | | @Override |
| | |
| | | if (CollectionUtils.isEmpty(ids)) { |
| | | return; |
| | | } |
| | | categoryMapper.deleteBatchIds(ids); |
| | | for(Integer id :ids){ |
| | | deleteById(id); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void updateById(Category category) { |
| | | categoryMapper.updateById(category); |
| | | if( category.getId() == null){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST); |
| | | } |
| | | if(Constants.equalsInteger(category.getId(),category.getParentId())){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,父级不能设置为自身!"); |
| | | } |
| | | category.setType(null);//类型不支持修改 |
| | | Category model = categoryMapper.selectById(category.getId()); |
| | | if(model ==null || Constants.equalsInteger(model.getIsdeleted(),Constants.ONE)) { |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY); |
| | | } |
| | | /* //查询名称不能重复 |
| | | if(categoryMapper.selectCount(new QueryWrapper<Category>().lambda() |
| | | .eq(Category::getName,category.getName()) |
| | | .eq(Category::getType,model.getType()) |
| | | .ne(Category::getId,category.getId()) |
| | | .eq(Category::getIsdeleted,Constants.ZERO)) >0){ |
| | | throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(), "对不起,名称不能重复~"); |
| | | }*/ |
| | | String oldIdPath = model.getIdPath(); |
| | | String oldNamePath = model.getNamePath(); |
| | | LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); |
| | | category.setIdPath(category.getId()+"/");//名称路径 |
| | | category.setNamePath(category.getName());//名称路径 |
| | | if(category.getParentId() !=null ){ |
| | | //如果父级发生改变 |
| | | Category parent = findById(category.getParentId()); |
| | | if(parent == null || Constants.equalsInteger(parent.getIsdeleted(),Constants.ONE)){ |
| | | throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(), "对不起,父级信息不存在~"); |
| | | } |
| | | category.setIdPath(parent.getIdPath()+category.getId()+"/"); |
| | | category.setNamePath(parent.getNamePath()+"/"+category.getName()); |
| | | } |
| | | category.setEditDate(new Date()); |
| | | category.setEditor(user.getId()); |
| | | categoryMapper.update(null,new UpdateWrapper<Category>().lambda() |
| | | .eq(Category::getId,category.getId()) |
| | | .set(Category::getEditDate,category.getEditDate()) |
| | | .set(Category::getEditor,category.getEditor()) |
| | | .set(Category::getName,category.getName()) |
| | | .set(Category::getParentId,category.getParentId()) |
| | | .set(Category::getSortnum,category.getSortnum()) |
| | | .set(Category::getRemark,category.getRemark()) |
| | | .set(Category::getNamePath,category.getNamePath()) |
| | | .set(Category::getIdPath,category.getId()) |
| | | ); |
| | | //修改全部下级的编码和名称路径 |
| | | categoryMapper.update(null,new UpdateWrapper<Category>().lambda() |
| | | .likeRight(Category::getIdPath,oldIdPath) |
| | | .set(Category::getEditDate,category.getEditDate()) |
| | | .set(Category::getEditor,category.getEditor()) |
| | | .setSql("id_path=replace(id_path,'"+oldIdPath+"','"+category.getIdParentPath()+"')") |
| | | .setSql("name_path=replace(name_path,'"+oldNamePath+"/','"+category.getName()+"/')") |
| | | ); |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | @Override |
| | | public List<Category> findList(Category category) { |
| | | QueryWrapper<Category> wrapper = new QueryWrapper<>(category); |
| | | return categoryMapper.selectList(wrapper); |
| | | category.setIsdeleted(Constants.ZERO); |
| | | MPJLambdaWrapper<Category> queryWrapper = new MPJLambdaWrapper<>(); |
| | | queryWrapper.selectAll(Category.class); |
| | | queryWrapper.selectAs(SystemUser::getUsername,Category::getEditorName); |
| | | queryWrapper.select("t1.name",Category::getParentName); |
| | | queryWrapper.select("t1.id_path",Category::getIdParentPath); |
| | | queryWrapper.leftJoin(Category.class,Category::getId,Category::getParentId); |
| | | queryWrapper.leftJoin(SystemUser.class,SystemUser::getId,Category::getEditor); |
| | | queryWrapper.eq(category.getId() != null, Category::getId, category.getId()) |
| | | .eq(category.getCreator() != null, Category::getCreator, category.getCreator()) |
| | | .ge(category.getCreateDate() != null, Category::getCreateDate, Utils.Date.getStart(category.getCreateDate())) |
| | | .le(category.getCreateDate() != null, Category::getCreateDate, Utils.Date.getEnd(category.getCreateDate())) |
| | | .eq(category.getEditor() != null, Category::getEditor, category.getEditor()) |
| | | .ge(category.getEditDate() != null, Category::getEditDate, Utils.Date.getStart(category.getEditDate())) |
| | | .le(category.getEditDate() != null, Category::getEditDate, Utils.Date.getEnd(category.getEditDate())) |
| | | .eq(category.getIsdeleted() != null, Category::getIsdeleted, category.getIsdeleted()) |
| | | .like(category.getName() != null, Category::getName, category.getName()) |
| | | .eq(category.getRemark() != null, Category::getRemark, category.getRemark()) |
| | | .eq(category.getStatus() != null, Category::getStatus, category.getStatus()) |
| | | .eq(category.getSortnum() != null, Category::getSortnum, category.getSortnum()) |
| | | .eq(category.getImgurl() != null, Category::getImgurl, category.getImgurl()) |
| | | .eq(category.getType() != null, Category::getType, category.getType()) |
| | | .eq(category.getParentId() != null, Category::getParentId, category.getParentId()) |
| | | .eq(category.getNamePath() != null, Category::getNamePath, category.getNamePath()) |
| | | .isNull(category.getIsRoot() != null &&category.getIsRoot().equals(Constants.ONE), Category::getParentId) |
| | | .eq(category.getIdPath() != null, Category::getIdPath, category.getIdPath()) |
| | | .orderByAsc( Category::getSortnum); |
| | | return categoryMapper.selectJoinList(Category.class,queryWrapper); |
| | | } |
| | | |
| | | @Override |
| | | public PageData<Category> findPage(PageWrap<Category> pageWrap) { |
| | | IPage<Category> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity()); |
| | | QueryWrapper<Category> queryWrapper = new QueryWrapper<>(); |
| | | Utils.MP.blankToNull(pageWrap.getModel()); |
| | | queryWrapper.lambda() |
| | | .eq(pageWrap.getModel().getId() != null, Category::getId, pageWrap.getModel().getId()) |
| | | pageWrap.getModel().setIsdeleted(Constants.ZERO); |
| | | MPJLambdaWrapper<Category> queryWrapper = new MPJLambdaWrapper<>(); |
| | | queryWrapper.selectAll(Category.class); |
| | | queryWrapper.selectAs(SystemUser::getUsername,Category::getEditorName); |
| | | queryWrapper.select("t1.name",Category::getParentName); |
| | | queryWrapper.select("t1.id_path",Category::getIdParentPath); |
| | | queryWrapper.leftJoin(Category.class,Category::getId,Category::getParentId); |
| | | queryWrapper.leftJoin(SystemUser.class,SystemUser::getId,Category::getEditor); |
| | | queryWrapper.eq(pageWrap.getModel().getId() != null, Category::getId, pageWrap.getModel().getId()) |
| | | .eq(pageWrap.getModel().getCreator() != null, Category::getCreator, pageWrap.getModel().getCreator()) |
| | | .ge(pageWrap.getModel().getCreateDate() != null, Category::getCreateDate, Utils.Date.getStart(pageWrap.getModel().getCreateDate())) |
| | | .le(pageWrap.getModel().getCreateDate() != null, Category::getCreateDate, Utils.Date.getEnd(pageWrap.getModel().getCreateDate())) |
| | |
| | | .ge(pageWrap.getModel().getEditDate() != null, Category::getEditDate, Utils.Date.getStart(pageWrap.getModel().getEditDate())) |
| | | .le(pageWrap.getModel().getEditDate() != null, Category::getEditDate, Utils.Date.getEnd(pageWrap.getModel().getEditDate())) |
| | | .eq(pageWrap.getModel().getIsdeleted() != null, Category::getIsdeleted, pageWrap.getModel().getIsdeleted()) |
| | | .eq(pageWrap.getModel().getName() != null, Category::getName, pageWrap.getModel().getName()) |
| | | .like(pageWrap.getModel().getName() != null, Category::getName, pageWrap.getModel().getName()) |
| | | .eq(pageWrap.getModel().getRemark() != null, Category::getRemark, pageWrap.getModel().getRemark()) |
| | | .eq(pageWrap.getModel().getStatus() != null, Category::getStatus, pageWrap.getModel().getStatus()) |
| | | .eq(pageWrap.getModel().getSortnum() != null, Category::getSortnum, pageWrap.getModel().getSortnum()) |
| | | .eq(pageWrap.getModel().getImgurl() != null, Category::getImgurl, pageWrap.getModel().getImgurl()) |
| | | .eq(pageWrap.getModel().getType() != null, Category::getType, pageWrap.getModel().getType()) |
| | | .eq(pageWrap.getModel().getParentId() != null, Category::getParentId, pageWrap.getModel().getParentId()) |
| | | .isNull(pageWrap.getModel().getIsRoot() != null && pageWrap.getModel().getIsRoot().equals(Constants.ONE), Category::getParentId) |
| | | .eq(pageWrap.getModel().getNamePath() != null, Category::getNamePath, pageWrap.getModel().getNamePath()) |
| | | .eq(pageWrap.getModel().getIdPath() != null, Category::getIdPath, pageWrap.getModel().getIdPath()) |
| | | ; |
| | | for(PageWrap.SortData sortData: pageWrap.getSorts()) { |
| | | if (sortData.getDirection().equalsIgnoreCase(PageWrap.DESC)) { |
| | | queryWrapper.orderByDesc(sortData.getProperty()); |
| | | } else { |
| | | queryWrapper.orderByAsc(sortData.getProperty()); |
| | | } |
| | | } |
| | | return PageData.from(categoryMapper.selectPage(page, queryWrapper)); |
| | | .orderByAsc( Category::getSortnum); |
| | | return PageData.from(categoryMapper.selectJoinPage(page,Category.class, queryWrapper)); |
| | | } |
| | | |
| | | @Override |
| | |
| | | QueryWrapper<Category> wrapper = new QueryWrapper<>(category); |
| | | return categoryMapper.selectCount(wrapper); |
| | | } |
| | | |
| | | @Override |
| | | public List<Category> treeList(Category param ) { |
| | | MPJLambdaWrapper<Category> queryWrapper = new MPJLambdaWrapper<>(); |
| | | queryWrapper.selectAll(Category.class); |
| | | queryWrapper.selectAs(SystemUser::getUsername,Category::getEditorName); |
| | | queryWrapper.select("t1.name",Category::getParentName); |
| | | queryWrapper.select("t1.id_path",Category::getIdParentPath); |
| | | queryWrapper.leftJoin(Category.class,Category::getId,Category::getParentId); |
| | | queryWrapper.leftJoin(SystemUser.class,SystemUser::getId,Category::getEditor); |
| | | queryWrapper.eq(Category::getIsdeleted, Constants.ZERO); |
| | | queryWrapper.eq(Category::getType, param.getType()); |
| | | queryWrapper.orderByAsc( Category::getSortnum); |
| | | List<Category> companyList = categoryMapper.selectJoinList(Category.class,queryWrapper); |
| | | CategoryTree treeBuild = new CategoryTree(companyList); |
| | | companyList = treeBuild.buildTree(); |
| | | return companyList; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | @Override |
| | | public List<CategoryVO> getCategoryVOTree(String categoryType,Integer categoryId){ |
| | | List<Category> categoryList = categoryMapper.selectList(new QueryWrapper<Category>().lambda() |
| | | .eq(Category::getIsdeleted, Constants.ZERO) |
| | | .in(Objects.nonNull(categoryType),Category::getType,categoryType.split(",")) |
| | | .apply(Objects.nonNull(categoryId)," find_in_set("+categoryId+", REPLACE(ID_PATH,'/',',') ) ") |
| | | .orderByAsc(Category::getSortnum,Category::getId) |
| | | ); |
| | | List<CategoryVO> categoryVOList = new ArrayList<>(); |
| | | if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(categoryList)){ |
| | | for (Category category:categoryList) { |
| | | CategoryVO categoryVO = new CategoryVO(); |
| | | categoryVO.setId(category.getId()); |
| | | categoryVO.setName(category.getName()); |
| | | categoryVO.setParentId(category.getParentId()); |
| | | categoryVOList.add(categoryVO); |
| | | } |
| | | CategoryVOTree treeBuild = new CategoryVOTree(categoryVOList); |
| | | categoryVOList = treeBuild.buildTree(); |
| | | } |
| | | return categoryVOList; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public List<CategoryVO> getCategoryVOForGCXTree(Integer categoryId){ |
| | | List<Category> categoryList = categoryMapper.selectList(new QueryWrapper<Category>().lambda() |
| | | .eq(Category::getIsdeleted, Constants.ZERO) |
| | | .eq(Category::getType, Constants.FOUR) |
| | | .and( ms->ms.eq(Category::getId,categoryId).or().eq(Category::getParentId,categoryId)) |
| | | .orderByAsc(Category::getSortnum,Category::getId) |
| | | ); |
| | | if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(categoryList)){ |
| | | categoryList.addAll( |
| | | categoryMapper.selectList(new QueryWrapper<Category>().lambda() |
| | | .eq(Category::getIsdeleted, Constants.ZERO) |
| | | .eq(Category::getType, Constants.SIX) |
| | | .in(Category::getParentId,categoryList.stream().map(i->i.getId()).collect(Collectors.toList())) |
| | | .orderByAsc(Category::getSortnum,Category::getId)) |
| | | ); |
| | | } |
| | | List<CategoryVO> categoryVOList = new ArrayList<>(); |
| | | if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(categoryList)){ |
| | | for (Category category:categoryList) { |
| | | CategoryVO categoryVO = new CategoryVO(); |
| | | categoryVO.setId(category.getId()); |
| | | categoryVO.setName(category.getName()); |
| | | categoryVO.setParentId(category.getParentId()); |
| | | categoryVOList.add(categoryVO); |
| | | } |
| | | CategoryVOTree treeBuild = new CategoryVOTree(categoryVOList); |
| | | categoryVOList = treeBuild.buildTree(); |
| | | } |
| | | return categoryVOList; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | @Override |
| | | public List<CategoryVO> getCategoryVOList(Integer categoryType,Integer isRoot){ |
| | | List<Category> categoryList = categoryMapper.selectList(new QueryWrapper<Category>().lambda() |
| | | .eq(Category::getIsdeleted, Constants.ZERO) |
| | | .eq(Objects.nonNull(categoryType),Category::getType,categoryType) |
| | | .isNull(Constants.equalsInteger(isRoot,Constants.ONE),Category::getParentId) |
| | | .orderByAsc(Category::getSortnum,Category::getId) |
| | | ); |
| | | List<CategoryVO> categoryVOList = new ArrayList<>(); |
| | | if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(categoryList)){ |
| | | for (Category category:categoryList) { |
| | | CategoryVO categoryVO = new CategoryVO(); |
| | | categoryVO.setId(category.getId()); |
| | | categoryVO.setName(category.getName()); |
| | | categoryVO.setParentId(category.getParentId()); |
| | | categoryVOList.add(categoryVO); |
| | | } |
| | | } |
| | | return categoryVOList; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | } |