package com.panzhihua.service_community.service.impl;
|
|
import static java.util.Objects.isNull;
|
|
import java.util.Date;
|
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.stereotype.Service;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.panzhihua.common.model.dtos.community.convenient.ConvenientProductCategoryDTO;
|
import com.panzhihua.common.model.dtos.community.convenient.PageConvenientProductCategoryDTO;
|
import com.panzhihua.common.model.vos.R;
|
import com.panzhihua.common.model.vos.community.convenient.ConvenientProductCategoryVO;
|
import com.panzhihua.service_community.dao.ConvenientProductCategoryDAO;
|
import com.panzhihua.service_community.model.dos.ConvenientProductCategoryDO;
|
import com.panzhihua.service_community.service.ConvenientProductCategoryService;
|
|
/**
|
* @title: ConvenientProductCategoryServiceImpl
|
* @projectName: 成都呐喊信息技术有限公司-智慧社区项目
|
* @description: 便民服务产品分类服务实现类
|
* @author: hans
|
* @date: 2021/09/20 16:13
|
*/
|
@Service
|
public class ConvenientProductCategoryServiceImpl extends ServiceImpl<ConvenientProductCategoryDAO, ConvenientProductCategoryDO> implements ConvenientProductCategoryService {
|
|
@Override
|
public R addProductCategory(ConvenientProductCategoryDTO convenientProductCategoryDTO) {
|
ConvenientProductCategoryDO convenientProductCategoryDO = new ConvenientProductCategoryDO();
|
BeanUtils.copyProperties(convenientProductCategoryDTO, convenientProductCategoryDO);
|
convenientProductCategoryDO.setCreatedAt(new Date());
|
int result = this.baseMapper.insert(convenientProductCategoryDO);
|
if (result > 0) {
|
return R.ok();
|
}
|
return R.fail("添加失败");
|
}
|
|
@Override
|
public R putProductCategory(ConvenientProductCategoryDTO convenientProductCategoryDTO) {
|
ConvenientProductCategoryDO convenientProductCategoryDO = this.baseMapper.selectById(convenientProductCategoryDTO.getId());
|
if (isNull(convenientProductCategoryDO)) {
|
return R.fail("分类id不存在");
|
}
|
BeanUtils.copyProperties(convenientProductCategoryDTO, convenientProductCategoryDO);
|
int result = this.baseMapper.updateById(convenientProductCategoryDO);
|
if (result > 0) {
|
return R.ok();
|
}
|
return R.fail("更新失败");
|
}
|
|
@Override
|
public R deleteProductCategory(Long categoryId, Long operator) {
|
if (isNull(categoryId)) {
|
return R.fail("分类id不能为空");
|
}
|
ConvenientProductCategoryDO convenientProductCategoryDO = this.baseMapper.selectById(categoryId);
|
if (isNull(convenientProductCategoryDO)) {
|
return R.fail("分类id不存在");
|
}
|
convenientProductCategoryDO.setIsDel(true);
|
convenientProductCategoryDO.setUpdatedBy(operator);
|
int result = this.baseMapper.updateById(convenientProductCategoryDO);
|
if (result > 0) {
|
return R.ok();
|
}
|
return R.fail("删除失败");
|
}
|
|
@Override
|
public R getProductCategory(Long categoryId) {
|
if (isNull(categoryId)) {
|
return R.fail("分类id不能为空");
|
}
|
ConvenientProductCategoryDO convenientProductCategoryDO = this.baseMapper.selectById(categoryId);
|
if (isNull(convenientProductCategoryDO)) {
|
return R.fail("分类id不存在");
|
}
|
ConvenientProductCategoryVO convenientProductCategoryVO = new ConvenientProductCategoryVO();
|
BeanUtils.copyProperties(convenientProductCategoryDO, convenientProductCategoryVO);
|
return R.ok(convenientProductCategoryVO);
|
}
|
|
@Override
|
public R pageProductCategory(PageConvenientProductCategoryDTO pageConvenientProductCategoryDTO) {
|
Page page = new Page<>();
|
page.setSize(pageConvenientProductCategoryDTO.getPageSize());
|
page.setCurrent(pageConvenientProductCategoryDTO.getPageNum());
|
IPage<ConvenientProductCategoryVO> iPage = this.baseMapper.pageProductCategory(page, pageConvenientProductCategoryDTO);
|
return R.ok(iPage);
|
}
|
|
@Override
|
public R getAllProductCategory() {
|
return R.ok(this.baseMapper.selectAllCategories());
|
}
|
}
|