@Override public int delete(Long id) { return productCategoryMapper.deleteByPrimaryKey(id); }
@Override public PmsProductCategory getItem(Long id) { return productCategoryMapper.selectByPrimaryKey(id); }
@Override public List<PmsProductCategory> getList(Long parentId, Integer pageSize, Integer pageNum) { PageHelper.startPage(pageNum, pageSize); PmsProductCategoryExample example = new PmsProductCategoryExample(); example.setOrderByClause("sort desc"); example.createCriteria().andParentIdEqualTo(parentId); return productCategoryMapper.selectByExample(example); }
@Override public int updateNavStatus(List<Long> ids, Integer navStatus) { PmsProductCategory productCategory = new PmsProductCategory(); productCategory.setNavStatus(navStatus); PmsProductCategoryExample example = new PmsProductCategoryExample(); example.createCriteria().andIdIn(ids); return productCategoryMapper.updateByExampleSelective(productCategory, example); }
@Override public int create(PmsProductCategoryParam pmsProductCategoryParam) { PmsProductCategory productCategory = new PmsProductCategory(); productCategory.setProductCount(0); BeanUtils.copyProperties(pmsProductCategoryParam, productCategory); //没有父分类时为一级分类 setCategoryLevel(productCategory); int count = productCategoryMapper.insertSelective(productCategory); //创建筛选属性关联 List<Long> productAttributeIdList = pmsProductCategoryParam.getProductAttributeIdList(); if(!CollectionUtils.isEmpty(productAttributeIdList)){ insertRelationList(productCategory.getId(), productAttributeIdList); } return count; }
@Override public int update(Long id, PmsProductCategoryParam pmsProductCategoryParam) { PmsProductCategory productCategory = new PmsProductCategory(); productCategory.setId(id); BeanUtils.copyProperties(pmsProductCategoryParam, productCategory); setCategoryLevel(productCategory); //更新商品分类时要更新商品中的名称 PmsProduct product = new PmsProduct(); product.setProductCategoryName(productCategory.getName()); PmsProductExample example = new PmsProductExample(); example.createCriteria().andProductCategoryIdEqualTo(id); productMapper.updateByExampleSelective(product,example); //同时更新筛选属性的信息 if(!CollectionUtils.isEmpty(pmsProductCategoryParam.getProductAttributeIdList())){ PmsProductCategoryAttributeRelationExample relationExample = new PmsProductCategoryAttributeRelationExample(); relationExample.createCriteria().andProductCategoryIdEqualTo(id); productCategoryAttributeRelationMapper.deleteByExample(relationExample); insertRelationList(id,pmsProductCategoryParam.getProductAttributeIdList()); }else{ PmsProductCategoryAttributeRelationExample relationExample = new PmsProductCategoryAttributeRelationExample(); relationExample.createCriteria().andProductCategoryIdEqualTo(id); productCategoryAttributeRelationMapper.deleteByExample(relationExample); } return productCategoryMapper.updateByPrimaryKeySelective(productCategory); }
@Override public List<PmsProductCategory> getProductCateList(Long parentId) { PmsProductCategoryExample example = new PmsProductCategoryExample(); example.createCriteria() .andShowStatusEqualTo(1) .andParentIdEqualTo(parentId); example.setOrderByClause("sort desc"); return productCategoryMapper.selectByExample(example); }
@Override public int updateShowStatus(List<Long> ids, Integer showStatus) { PmsProductCategory productCategory = new PmsProductCategory(); productCategory.setShowStatus(showStatus); PmsProductCategoryExample example = new PmsProductCategoryExample(); example.createCriteria().andIdIn(ids); return productCategoryMapper.updateByExampleSelective(productCategory, example); }
/** * 根据分类的parentId设置分类的level */ private void setCategoryLevel(PmsProductCategory productCategory) { //没有父分类时为一级分类 if (productCategory.getParentId() == 0) { productCategory.setLevel(0); } else { //有父分类时选择根据父分类level设置 PmsProductCategory parentCategory = productCategoryMapper.selectByPrimaryKey(productCategory.getParentId()); if (parentCategory != null) { productCategory.setLevel(parentCategory.getLevel() + 1); } else { productCategory.setLevel(0); } } } }