| | |
| | | package com.panzhihua.service_community.service.impl; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.ObjectUtils; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.panzhihua.common.model.dtos.community.ComCvtCategoryDTO; |
| | | import com.panzhihua.common.model.dtos.community.PageComCvtCategoryDTO; |
| | | import com.panzhihua.common.model.vos.R; |
| | | import com.panzhihua.common.model.vos.community.ComActVO; |
| | | import com.panzhihua.common.model.vos.community.ComCvtCategoryVO; |
| | | import com.panzhihua.service_community.dao.ComCvtCategoryDAO; |
| | | import com.panzhihua.service_community.model.dos.ComActDO; |
| | | import com.panzhihua.service_community.model.dos.ComCvtCategoryDO; |
| | | import com.panzhihua.service_community.service.ComCvtCategoryService; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.ObjectUtils; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @description: |
| | |
| | | |
| | | @Override |
| | | public R addComCvtCategory(ComCvtCategoryDTO comCvtCategoryDTO) { |
| | | ComCvtCategoryDO comCvtCategoryDO = comCvtCategoryDAO.selectOne(new QueryWrapper<ComCvtCategoryDO>().lambda().eq(ComCvtCategoryDO::getName,comCvtCategoryDTO.getName())); |
| | | if(null!=comCvtCategoryDO){ |
| | | ComCvtCategoryDO comCvtCategoryDO = comCvtCategoryDAO.selectOne( |
| | | new QueryWrapper<ComCvtCategoryDO>().lambda().eq(ComCvtCategoryDO::getName, comCvtCategoryDTO.getName())); |
| | | if (null != comCvtCategoryDO) { |
| | | return R.fail("分类名称重复"); |
| | | } |
| | | comCvtCategoryDO = new ComCvtCategoryDO(); |
| | | BeanUtils.copyProperties(comCvtCategoryDTO,comCvtCategoryDO); |
| | | BeanUtils.copyProperties(comCvtCategoryDTO, comCvtCategoryDO); |
| | | int count = comCvtCategoryDAO.insert(comCvtCategoryDO); |
| | | if(count<1){ |
| | | if (count < 1) { |
| | | return R.fail(); |
| | | } |
| | | return R.ok(); |
| | |
| | | @Override |
| | | public R putComCvtCategory(ComCvtCategoryDTO comCvtCategoryDTO) { |
| | | ComCvtCategoryDO old = comCvtCategoryDAO.selectById(comCvtCategoryDTO.getId()); |
| | | if(null==old){ |
| | | if (null == old) { |
| | | return R.fail("分类不存在"); |
| | | } |
| | | ComCvtCategoryDO comCvtCategoryDO = comCvtCategoryDAO.selectOne(new QueryWrapper<ComCvtCategoryDO>().lambda().eq(ComCvtCategoryDO::getName,comCvtCategoryDTO.getName())); |
| | | if(null!=comCvtCategoryDO && !old.getName().equals(comCvtCategoryDO.getName())){ |
| | | ComCvtCategoryDO comCvtCategoryDO = comCvtCategoryDAO.selectOne( |
| | | new QueryWrapper<ComCvtCategoryDO>().lambda().eq(ComCvtCategoryDO::getName, comCvtCategoryDTO.getName())); |
| | | if (null != comCvtCategoryDO && !old.getName().equals(comCvtCategoryDO.getName())) { |
| | | return R.fail("分类名称重复"); |
| | | } |
| | | BeanUtils.copyProperties(comCvtCategoryDTO,old); |
| | | BeanUtils.copyProperties(comCvtCategoryDTO, old); |
| | | int count = comCvtCategoryDAO.updateById(old); |
| | | if(count<1){ |
| | | if (count < 1) { |
| | | return R.fail(); |
| | | } |
| | | return R.ok(); |
| | |
| | | @Override |
| | | public R getComCvtCategory(Long id) { |
| | | ComCvtCategoryDO comCvtCategoryDO = comCvtCategoryDAO.selectById(id); |
| | | if(null==comCvtCategoryDO){ |
| | | if (null == comCvtCategoryDO) { |
| | | return R.fail("分类不存在"); |
| | | } |
| | | ComCvtCategoryVO comCvtCategoryVO = new ComCvtCategoryVO(); |
| | | BeanUtils.copyProperties(comCvtCategoryDO,comCvtCategoryVO); |
| | | BeanUtils.copyProperties(comCvtCategoryDO, comCvtCategoryVO); |
| | | return R.ok(comCvtCategoryVO); |
| | | } |
| | | |
| | | @Override |
| | | public R deleteComCvtCategory(Long id) { |
| | | ComCvtCategoryDO comCvtCategoryDO = comCvtCategoryDAO.selectById(id); |
| | | if(null==comCvtCategoryDO){ |
| | | if (null == comCvtCategoryDO) { |
| | | return R.fail("分类不存在"); |
| | | } |
| | | int count = comCvtCategoryDAO.deleteById(id); |
| | | if(count<1){ |
| | | if (count < 1) { |
| | | return R.fail("删除失败"); |
| | | } |
| | | return R.ok(); |
| | |
| | | @Override |
| | | public R allComCvtCategory() { |
| | | List<ComCvtCategoryVO> comCvtCategoryVOS = new ArrayList<>(); |
| | | List<ComCvtCategoryDO> categoryDOS = comCvtCategoryDAO.selectList(new QueryWrapper<ComCvtCategoryDO>().lambda().orderByDesc(ComCvtCategoryDO::getWeight)); |
| | | List<ComCvtCategoryDO> categoryDOS = comCvtCategoryDAO |
| | | .selectList(new QueryWrapper<ComCvtCategoryDO>().lambda().orderByDesc(ComCvtCategoryDO::getWeight)); |
| | | if (!ObjectUtils.isEmpty(categoryDOS)) { |
| | | categoryDOS.forEach(categoryDO -> { |
| | | ComCvtCategoryVO comCvtCategoryVO=new ComCvtCategoryVO(); |
| | | BeanUtils.copyProperties(categoryDO,comCvtCategoryVO); |
| | | ComCvtCategoryVO comCvtCategoryVO = new ComCvtCategoryVO(); |
| | | BeanUtils.copyProperties(categoryDO, comCvtCategoryVO); |
| | | comCvtCategoryVOS.add(comCvtCategoryVO); |
| | | }); |
| | | } |