| package doumeemes.service.ext.impl; | 
|   | 
| import com.github.pagehelper.PageHelper; | 
| import com.github.pagehelper.PageInfo; | 
| import doumeemes.core.model.LoginUserInfo; | 
| import doumeemes.core.model.PageData; | 
| import doumeemes.core.model.PageWrap; | 
| import doumeemes.core.utils.Constants; | 
| import doumeemes.core.utils.redis.RedisUtil; | 
| import doumeemes.dao.ext.CategoryExtMapper; | 
| import doumeemes.dao.ext.CompanyExtMapper; | 
| import doumeemes.dao.ext.dto.QueryBarcodeParamExtDTO; | 
| import doumeemes.dao.ext.dto.QueryCategoryExtDTO; | 
| import doumeemes.dao.ext.dto.QueryCompanyExtDTO; | 
| import doumeemes.dao.ext.vo.BarcodeParamExtListVO; | 
| import doumeemes.dao.ext.vo.CategoryExtListVO; | 
| import doumeemes.dao.ext.vo.CompanyExtListVO; | 
| import doumeemes.service.business.CategoryService; | 
| import doumeemes.service.ext.CategoryExtService; | 
| import org.apache.commons.lang3.StringUtils; | 
| import org.apache.shiro.SecurityUtils; | 
| import org.springframework.beans.factory.annotation.Autowired; | 
| import org.springframework.data.redis.core.RedisTemplate; | 
| import org.springframework.stereotype.Service; | 
|   | 
| import java.util.ArrayList; | 
| import java.util.List; | 
|   | 
| /** | 
|  * 设置类分类信息表Service实现 | 
|  * @author 江蹄蹄 | 
|  * @date 2022/04/27 16:15 | 
|  */ | 
| @Service | 
| public class CategoryExtServiceImpl implements CategoryExtService { | 
|     @Autowired | 
|     private RedisTemplate<String, Object> redisTemplate; | 
|     @Autowired | 
|     private CompanyExtMapper companyExtMapper; | 
|     @Autowired | 
|     private CategoryExtMapper categoryExtMapper; | 
|   | 
|   | 
|     @Override | 
|     public PageData<CategoryExtListVO> findPage(PageWrap<QueryCategoryExtDTO> pageWrap) { | 
|         PageHelper.startPage(pageWrap.getPage(), pageWrap.getCapacity()); | 
|         List<CategoryExtListVO> result = categoryExtMapper.selectList(pageWrap.getModel()); | 
|         return PageData.from(new PageInfo<>(result)); | 
|     } | 
|   | 
|     @Override | 
|     public List<CategoryExtListVO> findList(QueryCategoryExtDTO queryCategoryExtDTO) { | 
|         List<CategoryExtListVO> result = categoryExtMapper.selectList(queryCategoryExtDTO); | 
|         return result; | 
|     } | 
|   | 
|     @Override | 
|     public List<CategoryExtListVO> getListByType(String type,Integer rootDepartId,String cateType,String id) { | 
|         QueryCategoryExtDTO queryCategoryExtDTO=new QueryCategoryExtDTO(); | 
|         queryCategoryExtDTO.setDeleted(Constants.ZERO); | 
|         queryCategoryExtDTO.setType(type); | 
|         queryCategoryExtDTO.setRootDepartId(rootDepartId); | 
|         queryCategoryExtDTO.setCateType(cateType); | 
|         if(StringUtils.isNotEmpty(id)){ | 
|             queryCategoryExtDTO.setParentId(Integer.valueOf(id)); | 
|         } | 
|         List<CategoryExtListVO> result = categoryExtMapper.selectList(queryCategoryExtDTO); | 
|         return result; | 
|     } | 
|   | 
|     @Override | 
|     public  void loadCom(CompanyExtListVO com ) { | 
|         QueryCategoryExtDTO d = new QueryCategoryExtDTO(); | 
|         d.setDeleted(Constants.ZERO); | 
|         d.setCompanyId(com.getId()); | 
|         //查询全部企业部门信息 | 
|         List<CategoryExtListVO> clist = categoryExtMapper.selectList(d); | 
|         //加入redis缓存,以企业id为编码,缓存企业分类 | 
|         RedisUtil.addObject(redisTemplate,Constants.RedisKeys.COM_CATEGORY_KEY+com.getId(),clist); | 
|     } | 
|     @Override | 
|     public  CategoryExtListVO getByCategoryId(Integer comId, Integer id){ | 
|         if(comId==null || id == null){ | 
|             return null; | 
|         } | 
|         //查询缓存数据 | 
|         List<CategoryExtListVO> clist = RedisUtil.getObject(redisTemplate,Constants.RedisKeys.COM_CATEGORY_KEY+comId,ArrayList.class); | 
|         if(clist!=null){ | 
|             for(CategoryExtListVO model:clist){ | 
|                 if(Constants.equalsInteger(id,model.getId())){ | 
|                     return model; | 
|                 } | 
|             } | 
|         } | 
|         return null; | 
|     } | 
|     @Override | 
|     public     CategoryExtListVO getByCategoryId(Integer comId, Integer id,List<CategoryExtListVO> clist){ | 
|         if(comId==null || id == null){ | 
|             return null; | 
|         } | 
|         //查询缓存数据 | 
|         if(clist!=null){ | 
|             for(CategoryExtListVO model:clist){ | 
|                 if(Constants.equalsInteger(id,model.getId())){ | 
|                     return model; | 
|                 } | 
|             } | 
|         } | 
|         return null; | 
|     } | 
|     @Override | 
|     public List<CategoryExtListVO> treeCategoryList(QueryCategoryExtDTO param) { | 
|         LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); | 
|         param.setDeleted(Constants.ZERO); | 
|         param.setRootDepartId(user.getRootDepartment().getId()); | 
|         param.setCateType("0"); | 
|         List<CategoryExtListVO> list = categoryExtMapper.selectList(param); | 
|         List<CategoryExtListVO> bigAllList = getAllListByParentId("0",list); | 
|   | 
|             //查询所有的大类 | 
|             getCategoryDhildrenTree(bigAllList,list); | 
|   | 
|         return bigAllList; | 
|     } | 
|     private void getCategoryDhildrenTree(List<CategoryExtListVO> blist, List<CategoryExtListVO> list) { | 
|         if(blist!=null && blist.size()>0){ | 
|             for(CategoryExtListVO d : blist){ | 
|                     List<CategoryExtListVO> clist = getDepartListByParentId(d.getId(),list); | 
|                     d.setChildrenList(clist); | 
|                 getCategoryDhildrenTree(clist,list); | 
|             } | 
|   | 
|         } | 
|     } | 
|   | 
|   | 
|     private List<CategoryExtListVO> getDepartListByParentId(Integer pId, List<CategoryExtListVO> clist) { | 
|         List<CategoryExtListVO> list = null; | 
|         if(clist!= null){ | 
|             for(CategoryExtListVO d :clist){ | 
|                 if(Constants.equalsInteger(d.getParentId(),pId)){ | 
|                     if(list == null){ | 
|                         list = new ArrayList<>(); | 
|                     } | 
|                     list.add(d); | 
|                 } | 
|             } | 
|         } | 
|         return  list; | 
|     } | 
|   | 
|   | 
|     private List<CategoryExtListVO> getAllListByParentId(String type, List<CategoryExtListVO> clist) { | 
|         List<CategoryExtListVO> list = null; | 
|         if(clist!= null){ | 
|             for(CategoryExtListVO d :clist){ | 
|                 if(StringUtils.equals(type ,d.getType())){ | 
|                     if(list == null){ | 
|                         list = new ArrayList<>(); | 
|                     } | 
|                     list.add(d); | 
|                 } | 
|             } | 
|         } | 
|         return  list; | 
|     } | 
|   | 
|     @Override | 
|     public  void loadAll() { | 
|         QueryCompanyExtDTO dto = new QueryCompanyExtDTO(); | 
|         dto.setDeleted(Constants.ZERO); | 
|         //查询全部企业信息 | 
|         List<CompanyExtListVO> list =    companyExtMapper.selectList(dto); | 
|         if(list != null && list.size()>0){ | 
|             QueryCategoryExtDTO d = new QueryCategoryExtDTO(); | 
|             d.setDeleted(Constants.ZERO); | 
|             //查询全部企业信息 | 
|             List<CategoryExtListVO> codeList =    categoryExtMapper.selectList(d); | 
|             for(CompanyExtListVO com : list){ | 
|                 //当前企业的全部分类信息 | 
|                 List<CategoryExtListVO> clist = getAllByComId(com.getId(),codeList); | 
|                 //加入redis缓存,以企业id为编码,缓存企业二维码 | 
|                 RedisUtil.addObject(redisTemplate,Constants.RedisKeys.COM_CATEGORY_KEY+com.getId(),clist); | 
|             } | 
|         } | 
|     } | 
|   | 
|     private List<CategoryExtListVO> getAllByComId(Integer id, List<CategoryExtListVO> alllist) { | 
|         List<CategoryExtListVO> list = null; | 
|         if(alllist!= null){ | 
|             for(CategoryExtListVO d :alllist){ | 
|                 if(d.getCompanyId()!=null && Constants.equalsInteger(id,d.getCompanyId())){ | 
|                     if(list == null){ | 
|                         list = new ArrayList<>(); | 
|                     } | 
|                     list.add(d); | 
|                 } | 
|             } | 
|         } | 
|         return  list; | 
|     } | 
| } |