修改分类

This commit is contained in:
slhaf
2024-09-10 15:00:46 +08:00
parent 6dccaa379d
commit ae69dba64a
5 changed files with 177 additions and 7 deletions

View File

@@ -1,5 +1,6 @@
package com.sky.service;
import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.result.PageResult;
import org.springframework.stereotype.Service;
@@ -12,4 +13,29 @@ public interface CategoryService {
* @return
*/
PageResult pageQuery(CategoryPageQueryDTO categoryPageQueryDTO);
/**
* 新增分类
* @param categoryDTO
*/
void save(CategoryDTO categoryDTO);
/**
* 根据id删除分类
* @param id
*/
void deleteById(long id);
/**
* 启用、禁用分类
* @param status
* @param id
*/
void startOrStop(Integer status, long id);
/**
* 修改分类
* @param categoryDTO
*/
void update(CategoryDTO categoryDTO);
}

View File

@@ -2,14 +2,19 @@ package com.sky.service.impl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.sky.constant.StatusConstant;
import com.sky.context.BaseContext;
import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.mapper.CategoryMapper;
import com.sky.result.PageResult;
import com.sky.service.CategoryService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.List;
@Service
@@ -20,6 +25,7 @@ public class CategoryServiceImpl implements CategoryService {
/**
* 分类分页查询
*
* @param categoryPageQueryDTO
* @return
*/
@@ -33,6 +39,69 @@ public class CategoryServiceImpl implements CategoryService {
long total = page.getTotal();
List<Category> result = page.getResult();
return new PageResult(total,result);
return new PageResult(total, result);
}
/**
* 新增分类
*
* @param categoryDTO
*/
@Override
public void save(CategoryDTO categoryDTO) {
//复制属性
Category category = new Category();
BeanUtils.copyProperties(categoryDTO, category);
//补充属性
category.setStatus(StatusConstant.DISABLE);
category.setCreateTime(LocalDateTime.now());
category.setUpdateTime(LocalDateTime.now());
category.setCreateUser(BaseContext.getCurrentId());
category.setUpdateUser(BaseContext.getCurrentId());
categoryMapper.insert(category);
}
/**
* 根据id删除分类
*
* @param id
*/
@Override
public void deleteById(long id) {
categoryMapper.deleteById(id);
}
/**
* 启用、禁用分类
*
* @param status
* @param id
*/
@Override
public void startOrStop(Integer status, long id) {
Category category = Category.builder()
.id(id)
.status(status)
.build();
categoryMapper.update(category);
}
/**
* 修改分类
* @param categoryDTO
*/
@Override
public void update(CategoryDTO categoryDTO) {
//复制属性
Category category = new Category();
BeanUtils.copyProperties(categoryDTO, category);
//设置属性
category.setUpdateTime(LocalDateTime.now());
category.setUpdateUser(BaseContext.getCurrentId());
BaseContext.removeCurrentId();
categoryMapper.update(category);
}
}