|
@@ -0,0 +1,59 @@
|
|
|
+package com.chelvc.cloud.vehicle.server.service.impl;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.chelvc.cloud.vehicle.api.dto.CategoryDTO;
|
|
|
+import com.chelvc.cloud.vehicle.api.param.CategoryModifyParam;
|
|
|
+import com.chelvc.cloud.vehicle.api.param.CategoryPagingParam;
|
|
|
+import com.chelvc.cloud.vehicle.server.copier.CategoryCopier;
|
|
|
+import com.chelvc.cloud.vehicle.server.dao.CategoryMapper;
|
|
|
+import com.chelvc.cloud.vehicle.server.entity.Category;
|
|
|
+import com.chelvc.cloud.vehicle.server.service.CategoryService;
|
|
|
+import com.chelvc.framework.base.model.Pagination;
|
|
|
+import com.chelvc.framework.base.util.StringUtils;
|
|
|
+import com.chelvc.framework.database.context.DatabaseContextHolder;
|
|
|
+import com.chelvc.framework.database.util.PagingUtils;
|
|
|
+import lombok.NonNull;
|
|
|
+import org.apache.dubbo.config.annotation.DubboService;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 分类业务操作实现
|
|
|
+ *
|
|
|
+ * @author Woody
|
|
|
+ * @date 2023/5/2
|
|
|
+ */
|
|
|
+@DubboService(interfaceClass = com.chelvc.cloud.vehicle.api.service.CategoryService.class)
|
|
|
+public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements CategoryService,
|
|
|
+ com.chelvc.cloud.vehicle.api.service.CategoryService {
|
|
|
+ @Override
|
|
|
+ public Long addCategory(@NonNull CategoryModifyParam param) {
|
|
|
+ Category category = CategoryCopier.INSTANCE.copying(param);
|
|
|
+ this.save(category);
|
|
|
+ return category.getId();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void updateCategory(@NonNull Long id, @NonNull CategoryModifyParam param) {
|
|
|
+ Category category = DatabaseContextHolder.getRequireEntity(this, id, "分类不存在");
|
|
|
+ CategoryCopier.INSTANCE.copying(param, category);
|
|
|
+ this.updateById(category);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Pagination<CategoryDTO> getCategoryPaging(@NonNull CategoryPagingParam param) {
|
|
|
+ Page<Category> page = this.lambdaQuery()
|
|
|
+ .like(StringUtils.nonEmpty(param.getName()), Category::getName, param.getName())
|
|
|
+ .eq(Objects.nonNull(param.getEnabled()), Category::getEnabled, param.getEnabled())
|
|
|
+ .orderByAsc(Category::getSort).page(PagingUtils.convert(param.getPaging()));
|
|
|
+ return PagingUtils.convert(page, CategoryCopier.INSTANCE::copying);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<CategoryDTO> listActiveCategories() {
|
|
|
+ List<Category> categories = this.lambdaQuery().eq(Category::getEnabled, true).list();
|
|
|
+ return CategoryCopier.INSTANCE.copying(categories);
|
|
|
+ }
|
|
|
+}
|