| | |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.apache.shiro.SecurityUtils; |
| | | import org.checkerframework.checker.units.qual.C; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.validation.BindException; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | |
| | | private CategoryMapper categoryMapper; |
| | | |
| | | @Override |
| | | public Integer create(Category category) { |
| | | @Transactional(rollbackFor = {Exception.class, BindException.class}) |
| | | public Integer create(Category category){ |
| | | checkUnique(category); |
| | | LoginUserInfo loginUserInfo = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); |
| | | if(loginUserInfo ==null){ |
| | |
| | | insert.setType(category.getType()); |
| | | insert.setParentId(category.getParentId()); |
| | | categoryMapper.insert(insert); |
| | | if(insert.getBizType()!=null){ |
| | | //清空其他bizType,只保留当前新增记录唯一有效 |
| | | categoryMapper.update(null,new UpdateWrapper<Category>().lambda() |
| | | .set(Category::getBizType,null) |
| | | .ne(Category::getId,insert.getId()) |
| | | ); |
| | | } |
| | | return insert.getId(); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = {Exception.class, BindException.class}) |
| | | public void updateById(Category category) { |
| | | checkUnique(category); |
| | | categoryMapper.updateById(category); |
| | | if(category.getBizType()!=null){ |
| | | //清空其他该bizType属性,只保留当前记录唯一有效 |
| | | categoryMapper.update(null,new UpdateWrapper<Category>().lambda() |
| | | .set(Category::getBizType,null) |
| | | .ne(Category::getId,category.getId()) |
| | | ); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | |
| | | wrapper.lambda() |
| | | .eq(Category::getIsdeleted,Constants.ZERO) |
| | | .eq(Category::getType,category.getType()) |
| | | .eq(Category::getName,category.getName()); |
| | | .eq(Category::getName,category.getName()) |
| | | .ne(category.getId()!=null, Category::getId,category.getId()) |
| | | ; |
| | | |
| | | List<Category> categories = categoryMapper.selectList(wrapper); |
| | | |
| | | if (org.apache.commons.collections.CollectionUtils.isNotEmpty(categories)){ |
| | | throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"分类信息已存在"); |
| | | } |