| package doumeemes.service.business.impl; | 
|   | 
| 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 doumeemes.core.model.ApiResponse; | 
| import doumeemes.core.model.LoginUserInfo; | 
| import doumeemes.core.model.PageData; | 
| import doumeemes.core.model.PageWrap; | 
| import doumeemes.core.utils.Constants; | 
| import doumeemes.core.utils.Utils; | 
| import doumeemes.dao.business.CategoryUnionMapper; | 
| import doumeemes.dao.business.model.CategoryUnion; | 
| import doumeemes.service.business.CategoryUnionService; | 
| 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; | 
|   | 
| /** | 
|  * 物料分类组合信息表Service实现 | 
|  * @author 江蹄蹄 | 
|  * @date 2022/04/27 16:15 | 
|  */ | 
| @Service | 
| public class CategoryUnionServiceImpl implements CategoryUnionService { | 
|   | 
|     @Autowired | 
|     private CategoryUnionMapper categoryUnionMapper; | 
|     @Autowired | 
|     private CategoryServiceImpl categoryServiceimpl; | 
|   | 
|     @Override | 
|     public Integer create(CategoryUnion categoryUnion) { | 
|         categoryUnionMapper.insert(categoryUnion); | 
|         return categoryUnion.getId(); | 
|     } | 
|   | 
|     @Override | 
|     public void deleteById(Integer id) { | 
|         categoryUnionMapper.deleteById(id); | 
|     } | 
|   | 
|     @Override | 
|     public void delete(CategoryUnion categoryUnion) { | 
|         UpdateWrapper<CategoryUnion> deleteWrapper = new UpdateWrapper<>(categoryUnion); | 
|         categoryUnionMapper.delete(deleteWrapper); | 
|     } | 
|   | 
|     @Override | 
|     public void deleteByIdInBatch(List<Integer> ids) { | 
|         if (CollectionUtils.isEmpty(ids)) { | 
|             return; | 
|         } | 
|         categoryUnionMapper.deleteBatchIds(ids); | 
|     } | 
|   | 
|     @Override | 
|     public void updateById(CategoryUnion categoryUnion) { | 
|         categoryUnionMapper.updateById(categoryUnion); | 
|     } | 
|   | 
|     @Override | 
|     public void updateByIdInBatch(List<CategoryUnion> categoryUnions) { | 
|         if (CollectionUtils.isEmpty(categoryUnions)) { | 
|             return; | 
|         } | 
|         for (CategoryUnion categoryUnion: categoryUnions) { | 
|             this.updateById(categoryUnion); | 
|         } | 
|     } | 
|   | 
|     @Override | 
|     public CategoryUnion findById(Integer id) { | 
|         return categoryUnionMapper.selectById(id); | 
|     } | 
|   | 
|     @Override | 
|     public CategoryUnion findOne(CategoryUnion categoryUnion) { | 
|         QueryWrapper<CategoryUnion> wrapper = new QueryWrapper<>(categoryUnion); | 
|         return categoryUnionMapper.selectOne(wrapper); | 
|     } | 
|   | 
|     @Override | 
|     public List<CategoryUnion> findList(CategoryUnion categoryUnion) { | 
|         QueryWrapper<CategoryUnion> wrapper = new QueryWrapper<>(categoryUnion); | 
|         return categoryUnionMapper.selectList(wrapper); | 
|     } | 
|    | 
|     @Override | 
|     public PageData<CategoryUnion> findPage(PageWrap<CategoryUnion> pageWrap) { | 
|         IPage<CategoryUnion> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity()); | 
|         QueryWrapper<CategoryUnion> queryWrapper = new QueryWrapper<>(); | 
|         Utils.MP.blankToNull(pageWrap.getModel()); | 
|         if (pageWrap.getModel().getId() != null) { | 
|             queryWrapper.lambda().eq(CategoryUnion::getId, pageWrap.getModel().getId()); | 
|         } | 
|         if (pageWrap.getModel().getDeleted() != null) { | 
|             queryWrapper.lambda().eq(CategoryUnion::getDeleted, pageWrap.getModel().getDeleted()); | 
|         } | 
|         if (pageWrap.getModel().getCreateUser() != null) { | 
|             queryWrapper.lambda().eq(CategoryUnion::getCreateUser, pageWrap.getModel().getCreateUser()); | 
|         } | 
|         if (pageWrap.getModel().getCreateTime() != null) { | 
|             queryWrapper.lambda().ge(CategoryUnion::getCreateTime, Utils.Date.getStart(pageWrap.getModel().getCreateTime())); | 
|             queryWrapper.lambda().le(CategoryUnion::getCreateTime, Utils.Date.getEnd(pageWrap.getModel().getCreateTime())); | 
|         } | 
|         if (pageWrap.getModel().getUpdateUser() != null) { | 
|             queryWrapper.lambda().eq(CategoryUnion::getUpdateUser, pageWrap.getModel().getUpdateUser()); | 
|         } | 
|         if (pageWrap.getModel().getUpdateTime() != null) { | 
|             queryWrapper.lambda().ge(CategoryUnion::getUpdateTime, Utils.Date.getStart(pageWrap.getModel().getUpdateTime())); | 
|             queryWrapper.lambda().le(CategoryUnion::getUpdateTime, Utils.Date.getEnd(pageWrap.getModel().getUpdateTime())); | 
|         } | 
|         if (pageWrap.getModel().getRemark() != null) { | 
|             queryWrapper.lambda().eq(CategoryUnion::getRemark, pageWrap.getModel().getRemark()); | 
|         } | 
|         if (pageWrap.getModel().getRootDepartId() != null) { | 
|             queryWrapper.lambda().eq(CategoryUnion::getRootDepartId, pageWrap.getModel().getRootDepartId()); | 
|         } | 
|         if (pageWrap.getModel().getCateBigId() != null) { | 
|             queryWrapper.lambda().eq(CategoryUnion::getCateBigId, pageWrap.getModel().getCateBigId()); | 
|         } | 
|         if (pageWrap.getModel().getCateMiddleId() != null) { | 
|             queryWrapper.lambda().eq(CategoryUnion::getCateMiddleId, pageWrap.getModel().getCateMiddleId()); | 
|         } | 
|         if (pageWrap.getModel().getCateSmallId() != null) { | 
|             queryWrapper.lambda().eq(CategoryUnion::getCateSmallId, pageWrap.getModel().getCateSmallId()); | 
|         } | 
|         for(PageWrap.SortData sortData: pageWrap.getSorts()) { | 
|             if (sortData.getDirection().equalsIgnoreCase(PageWrap.DESC)) { | 
|                 queryWrapper.orderByDesc(sortData.getProperty()); | 
|             } else { | 
|                 queryWrapper.orderByAsc(sortData.getProperty()); | 
|             } | 
|         } | 
|         return PageData.from(categoryUnionMapper.selectPage(page, queryWrapper)); | 
|     } | 
|   | 
|     @Override | 
|     public long count(CategoryUnion categoryUnion) { | 
|         QueryWrapper<CategoryUnion> wrapper = new QueryWrapper<>(categoryUnion); | 
|         return categoryUnionMapper.selectCount(wrapper); | 
|     } | 
|   | 
|     @Override | 
|     public ApiResponse insertData(CategoryUnion categoryUnion) { | 
|         LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); | 
|         categoryUnion.setDeleted(Constants.ZERO); | 
|         categoryUnion.setRootDepartId(user.getRootDepartment().getId()); | 
|         categoryUnion.setCreateTime(new Date()); | 
|         categoryUnion.setCreateUser(user.getId()); | 
|   | 
|         CategoryUnion cu=new CategoryUnion(); | 
|         cu.setCateBigId(categoryUnion.getCateBigId()); | 
|         cu.setCateMiddleId(categoryUnion.getCateMiddleId()); | 
|         cu.setCateSmallId(categoryUnion.getCateSmallId()); | 
|         cu.setRootDepartId(user.getRootDepartment().getId()); | 
|         cu.setDeleted(Constants.ZERO); | 
|         List<CategoryUnion> find=  this.findList(cu); | 
|         if(find!=null&&find.size()>0){ | 
|             return ApiResponse.failed("组合已存在不允许添加"); | 
|         } | 
|         categoryUnionMapper.insert(categoryUnion); | 
|         return ApiResponse.success(categoryUnion.getId()); | 
|     } | 
|   | 
|   | 
|     @Override | 
|     public ApiResponse editById(CategoryUnion categoryUnion) { | 
|         LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); | 
|         CategoryUnion cu=new CategoryUnion(); | 
|         cu.setCateBigId(categoryUnion.getCateBigId()); | 
|         cu.setCateMiddleId(categoryUnion.getCateMiddleId()); | 
|         cu.setCateSmallId(categoryUnion.getCateSmallId()); | 
|         cu.setRootDepartId(user.getRootDepartment().getId()); | 
|         cu.setDeleted(Constants.ZERO); | 
|         List<CategoryUnion> findList=  this.findList(cu); | 
|         if(findList!=null&&findList.size()>0){ | 
|             if(!Constants.equalsInteger(findList.get(0).getId(),categoryUnion.getId())){ | 
|                 return ApiResponse.failed("组合已存在不允许添加"); | 
|             } | 
|         } | 
|   | 
|         CategoryUnion find=  this.findById(categoryUnion.getId()); | 
|         find.setUpdateTime(new Date()); | 
|         find.setUpdateUser(user.getId()); | 
|         find.setCateBigId(categoryUnion.getCateBigId()); | 
|         find.setCateMiddleId(categoryUnion.getCateMiddleId()); | 
|         find.setCateSmallId(categoryUnion.getCateSmallId()); | 
|   | 
|         categoryUnionMapper.updateById(categoryUnion); | 
|         return ApiResponse.success(null); | 
|     } | 
| } |