| | |
| | | package com.doumee.service.business.impl; |
| | | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.doumee.biz.system.SystemDictDataBiz; |
| | | 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.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.base.MPJBaseMapper; |
| | | import com.github.yulichang.wrapper.MPJLambdaWrapper; |
| | | 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 java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | |
| | | /** |
| | | * 分类信息表Service实现 |
| | |
| | | @Autowired |
| | | private CategoryMapper categoryMapper; |
| | | |
| | | @Autowired |
| | | private SystemDictDataBiz systemDictDataBiz; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = {Exception.class,BusinessException.class}) |
| | | public Integer create(Category category) { |
| | | if(Objects.isNull(category) |
| | | || Objects.isNull(category.getType()) |
| | | || Objects.isNull(category.getName()) |
| | | || (!Constants.equalsInteger(category.getType(),Constants.ZERO)&& CollectionUtils.isEmpty(category.getDetailList())) |
| | | || (Constants.equalsInteger(category.getType(),Constants.ONE) && (Objects.isNull(category.getIcon())||Objects.isNull(category.getIsFixed())) ) |
| | | ){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST); |
| | | } |
| | | LoginUserInfo loginUserInfo = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); |
| | | category.setDeleted(Constants.ZERO); |
| | | category.setCreateTime(new Date()); |
| | | category.setCreateUser(loginUserInfo.getId()); |
| | | category.setUpdateTime(new Date()); |
| | | category.setUpdateUser(loginUserInfo.getId()); |
| | | if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(category.getDetailList()) |
| | | && !Constants.equalsInteger(category.getType(),Constants.THREE)){ |
| | | category.setDetail(category.getDetailList().toJSONString()); |
| | | } |
| | | if(!Constants.equalsInteger(category.getType(),Constants.ONE)){ |
| | | category.setIsFixed(Constants.ZERO); |
| | | } |
| | | categoryMapper.insert(category); |
| | | return category.getId(); |
| | | } |
| | | |
| | | @Override |
| | | public void deleteById(Integer id) { |
| | | categoryMapper.deleteById(id); |
| | | categoryMapper.update(new UpdateWrapper<Category>().lambda().set(Category::getDeleted,Constants.ONE).eq(Category::getId,id)); |
| | | |
| | | // categoryMapper.deleteById(id); |
| | | } |
| | | |
| | | @Override |
| | |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = {Exception.class,BusinessException.class}) |
| | | public void updateById(Category category) { |
| | | if(Objects.isNull(category) |
| | | || Objects.isNull(category.getId()) |
| | | || Objects.isNull(category.getType()) |
| | | || Objects.isNull(category.getName()) |
| | | || (!Constants.equalsInteger(category.getType(),Constants.ZERO)&& CollectionUtils.isEmpty(category.getDetailList())) |
| | | || (Constants.equalsInteger(category.getType(),Constants.ONE) && (Objects.isNull(category.getIcon())||Objects.isNull(category.getIsFixed())) ) |
| | | ){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST); |
| | | } |
| | | LoginUserInfo loginUserInfo = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); |
| | | category.setUpdateTime(new Date()); |
| | | category.setIsFixed(null); |
| | | category.setUpdateUser(loginUserInfo.getId()); |
| | | if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(category.getDetailList()) |
| | | && !Constants.equalsInteger(category.getType(),Constants.THREE)){ |
| | | category.setDetail(category.getDetailList().toJSONString()); |
| | | } |
| | | categoryMapper.updateById(category); |
| | | } |
| | | @Override |
| | | public void updateStatus(Category category) { |
| | | if(Objects.isNull(category) |
| | | || Objects.isNull(category.getId())){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST); |
| | | } |
| | | LoginUserInfo loginUserInfo = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); |
| | | category.setUpdateTime(new Date()); |
| | | category.setIsFixed(null); |
| | | category.setUpdateUser(loginUserInfo.getId()); |
| | | if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(category.getDetailList())){ |
| | | category.setDetail(category.getDetailList().toJSONString()); |
| | | } |
| | | categoryMapper.updateById(category); |
| | | } |
| | | |
| | |
| | | |
| | | @Override |
| | | public Category findById(Integer id) { |
| | | return categoryMapper.selectById(id); |
| | | Category category = categoryMapper.selectById(id); |
| | | if(Objects.isNull(category)){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY); |
| | | } |
| | | if(StringUtils.isNotBlank(category.getDetail())){ |
| | | category.setDetailList(JSONArray.parseArray(category.getDetail())); |
| | | } |
| | | if(StringUtils.isNotBlank(category.getIcon())){ |
| | | String path = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.RESOURCE_PATH).getCode() |
| | | +systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.CATEGORY_FILES).getCode(); |
| | | category.setIconFull(path + category.getIcon()); |
| | | } |
| | | return category; |
| | | } |
| | | |
| | | @Override |
| | |
| | | @Override |
| | | public PageData<Category> findPage(PageWrap<Category> pageWrap) { |
| | | IPage<Category> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity()); |
| | | QueryWrapper<Category> queryWrapper = new QueryWrapper<>(); |
| | | MPJLambdaWrapper<Category> queryWrapper = new MPJLambdaWrapper<>(); |
| | | Utils.MP.blankToNull(pageWrap.getModel()); |
| | | pageWrap.getModel().setDeleted(Constants.ZERO); |
| | | queryWrapper.selectAll(Category.class) |
| | | .selectAs(SystemUser::getUsername, Category::getUpdateUserName) |
| | | .leftJoin(SystemUser.class,SystemUser::getId,Category::getUpdateUser); |
| | | if (pageWrap.getModel().getId() != null) { |
| | | queryWrapper.lambda().eq(Category::getId, pageWrap.getModel().getId()); |
| | | queryWrapper.eq(Category::getId, pageWrap.getModel().getId()); |
| | | } |
| | | if (pageWrap.getModel().getDeleted() != null) { |
| | | queryWrapper.lambda().eq(Category::getDeleted, pageWrap.getModel().getDeleted()); |
| | | queryWrapper.eq(Category::getDeleted, pageWrap.getModel().getDeleted()); |
| | | } |
| | | if (pageWrap.getModel().getStatus() != null) { |
| | | queryWrapper.lambda().eq(Category::getStatus, pageWrap.getModel().getStatus()); |
| | | queryWrapper.eq(Category::getStatus, pageWrap.getModel().getStatus()); |
| | | } |
| | | if (pageWrap.getModel().getCreateUser() != null) { |
| | | queryWrapper.lambda().eq(Category::getCreateUser, pageWrap.getModel().getCreateUser()); |
| | | queryWrapper.eq(Category::getCreateUser, pageWrap.getModel().getCreateUser()); |
| | | } |
| | | if (pageWrap.getModel().getCreateTime() != null) { |
| | | queryWrapper.lambda().ge(Category::getCreateTime, Utils.Date.getStart(pageWrap.getModel().getCreateTime())); |
| | | queryWrapper.lambda().le(Category::getCreateTime, Utils.Date.getEnd(pageWrap.getModel().getCreateTime())); |
| | | queryWrapper.ge(Category::getCreateTime, Utils.Date.getStart(pageWrap.getModel().getCreateTime())); |
| | | queryWrapper.le(Category::getCreateTime, Utils.Date.getEnd(pageWrap.getModel().getCreateTime())); |
| | | } |
| | | if (pageWrap.getModel().getUpdateUser() != null) { |
| | | queryWrapper.lambda().eq(Category::getUpdateUser, pageWrap.getModel().getUpdateUser()); |
| | | queryWrapper.eq(Category::getUpdateUser, pageWrap.getModel().getUpdateUser()); |
| | | } |
| | | if (pageWrap.getModel().getUpdateTime() != null) { |
| | | queryWrapper.lambda().ge(Category::getUpdateTime, Utils.Date.getStart(pageWrap.getModel().getUpdateTime())); |
| | | queryWrapper.lambda().le(Category::getUpdateTime, Utils.Date.getEnd(pageWrap.getModel().getUpdateTime())); |
| | | queryWrapper.ge(Category::getUpdateTime, Utils.Date.getStart(pageWrap.getModel().getUpdateTime())); |
| | | queryWrapper.le(Category::getUpdateTime, Utils.Date.getEnd(pageWrap.getModel().getUpdateTime())); |
| | | } |
| | | if (pageWrap.getModel().getRemark() != null) { |
| | | queryWrapper.lambda().eq(Category::getRemark, pageWrap.getModel().getRemark()); |
| | | queryWrapper.eq(Category::getRemark, pageWrap.getModel().getRemark()); |
| | | } |
| | | if (pageWrap.getModel().getName() != null) { |
| | | queryWrapper.lambda().eq(Category::getName, pageWrap.getModel().getName()); |
| | | queryWrapper.like(Category::getName, pageWrap.getModel().getName()); |
| | | } |
| | | if (pageWrap.getModel().getType() != null) { |
| | | queryWrapper.lambda().eq(Category::getType, pageWrap.getModel().getType()); |
| | | queryWrapper.eq(Category::getType, pageWrap.getModel().getType()); |
| | | } |
| | | if (pageWrap.getModel().getDetail() != null) { |
| | | queryWrapper.lambda().eq(Category::getDetail, pageWrap.getModel().getDetail()); |
| | | queryWrapper.eq(Category::getDetail, pageWrap.getModel().getDetail()); |
| | | } |
| | | if (pageWrap.getModel().getIcon() != null) { |
| | | queryWrapper.lambda().eq(Category::getIcon, pageWrap.getModel().getIcon()); |
| | | queryWrapper.eq(Category::getIcon, pageWrap.getModel().getIcon()); |
| | | } |
| | | if (pageWrap.getModel().getIsFixed() != null) { |
| | | queryWrapper.lambda().eq(Category::getIsFixed, pageWrap.getModel().getIsFixed()); |
| | | queryWrapper.eq(Category::getIsFixed, pageWrap.getModel().getIsFixed()); |
| | | } |
| | | for(PageWrap.SortData sortData: pageWrap.getSorts()) { |
| | | if (sortData.getDirection().equalsIgnoreCase(PageWrap.DESC)) { |
| | | queryWrapper.orderByDesc(sortData.getProperty()); |
| | | } else { |
| | | queryWrapper.orderByAsc(sortData.getProperty()); |
| | | queryWrapper.orderByAsc(Category::getSortnum); |
| | | PageData<Category> result =PageData.from(categoryMapper.selectJoinPage(page, Category.class,queryWrapper)); |
| | | if(result!=null && result.getRecords()!=null){ |
| | | String path = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.RESOURCE_PATH).getCode() |
| | | +systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.CATEGORY_FILES).getCode(); |
| | | for(Category cate : result.getRecords()){ |
| | | try { |
| | | if(StringUtils.isNotBlank(cate.getDetail())){ |
| | | cate.setDetailList(JSONArray.parseArray(cate.getDetail())); |
| | | } |
| | | if(StringUtils.isNotBlank(cate.getIcon())){ |
| | | cate.setIconFull(path + cate.getIcon()); |
| | | } |
| | | }catch (Exception e){ |
| | | |
| | | } |
| | | } |
| | | } |
| | | return PageData.from(categoryMapper.selectPage(page, queryWrapper)); |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | |
| | | QueryWrapper<Category> wrapper = new QueryWrapper<>(category); |
| | | return categoryMapper.selectCount(wrapper); |
| | | } |
| | | |
| | | @Override |
| | | public List<Category> getCategoryList(Integer type){ |
| | | List<Category> categoryList = categoryMapper.selectList(new QueryWrapper<Category>().lambda().eq(Category::getDeleted,Constants.ZERO).eq(Category::getStatus,Constants.ZERO) |
| | | .eq(Objects.nonNull(type),Category::getType,type) |
| | | .orderByAsc(Category::getSortnum) |
| | | ); |
| | | if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(categoryList)){ |
| | | String path = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.RESOURCE_PATH).getCode() |
| | | +systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.CATEGORY_FILES).getCode(); |
| | | for (Category category:categoryList) { |
| | | if(StringUtils.isNotBlank(category.getDetail())){ |
| | | category.setDetailList(JSONArray.parseArray(category.getDetail())); |
| | | } |
| | | if(StringUtils.isNotBlank(category.getIcon())){ |
| | | category.setIconFull(path + category.getIcon()); |
| | | } |
| | | } |
| | | } |
| | | return categoryList; |
| | | } |
| | | |
| | | |
| | | } |