|  |  |  | 
|---|
|  |  |  | package com.doumee.service.business.impl; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 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.Constants; | 
|---|
|  |  |  | import com.doumee.core.utils.Utils; | 
|---|
|  |  |  | import com.doumee.dao.business.CategoryMapper; | 
|---|
|  |  |  | import com.doumee.dao.business.model.Category; | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.metadata.IPage; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 
|---|
|  |  |  | 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.Date; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public Integer create(Category category) { | 
|---|
|  |  |  | categoryMapper.insert(category); | 
|---|
|  |  |  | return category.getId(); | 
|---|
|  |  |  | checkUnique(category); | 
|---|
|  |  |  | LoginUserInfo loginUserInfo = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); | 
|---|
|  |  |  | Category insert = new Category(); | 
|---|
|  |  |  | insert.setCreator(loginUserInfo.getId()); | 
|---|
|  |  |  | insert.setCreateDate(new Date()); | 
|---|
|  |  |  | insert.setEditor(loginUserInfo.getId()); | 
|---|
|  |  |  | insert.setEditDate(new Date()); | 
|---|
|  |  |  | insert.setIsdeleted(Constants.ZERO); | 
|---|
|  |  |  | insert.setName(category.getName()); | 
|---|
|  |  |  | insert.setRemark(category.getRemark()); | 
|---|
|  |  |  | insert.setStatus(Constants.ZERO); | 
|---|
|  |  |  | insert.setSortnum(category.getSortnum()); | 
|---|
|  |  |  | insert.setImgurl(category.getImgurl()); | 
|---|
|  |  |  | insert.setType(Constants.ZERO); | 
|---|
|  |  |  | insert.setParentId(category.getParentId()); | 
|---|
|  |  |  | categoryMapper.insert(insert); | 
|---|
|  |  |  | return insert.getId(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void updateById(Category category) { | 
|---|
|  |  |  | checkUnique(category); | 
|---|
|  |  |  | categoryMapper.updateById(category); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | QueryWrapper<Category> wrapper = new QueryWrapper<>(category); | 
|---|
|  |  |  | return categoryMapper.selectList(wrapper); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public PageData<Category> findPage(PageWrap<Category> pageWrap) { | 
|---|
|  |  |  | IPage<Category> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity()); | 
|---|
|  |  |  | 
|---|
|  |  |  | QueryWrapper<Category> wrapper = new QueryWrapper<>(category); | 
|---|
|  |  |  | return categoryMapper.selectCount(wrapper); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private void checkUnique(Category category){ | 
|---|
|  |  |  | QueryWrapper<Category> wrapper = new QueryWrapper<>(); | 
|---|
|  |  |  | wrapper.lambda() | 
|---|
|  |  |  | .eq(Category::getIsdeleted,Constants.ZERO) | 
|---|
|  |  |  | .eq(Category::getType,category.getType()) | 
|---|
|  |  |  | .eq(Category::getName,category.getName()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<Category> categories = categoryMapper.selectList(wrapper); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (org.apache.commons.collections.CollectionUtils.isNotEmpty(categories)){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"分类信息已存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|