From 09e41d546b030b47661877d4b8141c88584d7598 Mon Sep 17 00:00:00 2001
From: 罗元桥 <2376770955@qq.com>
Date: 星期五, 24 九月 2021 16:03:52 +0800
Subject: [PATCH] Merge branch 'test' into 'four_member'

---
 springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ConvenientServiceCategoryServiceImpl.java |  126 ++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 126 insertions(+), 0 deletions(-)

diff --git a/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ConvenientServiceCategoryServiceImpl.java b/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ConvenientServiceCategoryServiceImpl.java
new file mode 100644
index 0000000..d242ed2
--- /dev/null
+++ b/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ConvenientServiceCategoryServiceImpl.java
@@ -0,0 +1,126 @@
+package com.panzhihua.service_community.service.impl;
+
+import static java.util.Objects.isNull;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+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.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.panzhihua.common.model.dtos.community.convenient.ConvenientServiceCategoryDTO;
+import com.panzhihua.common.model.dtos.community.convenient.PageConvenientServiceCategoryDTO;
+import com.panzhihua.common.model.vos.R;
+import com.panzhihua.common.model.vos.community.convenient.ConvenientServiceCategoryVO;
+import com.panzhihua.service_community.dao.ConvenientServiceCategoryDAO;
+import com.panzhihua.service_community.model.dos.ConvenientServiceCategoryDO;
+import com.panzhihua.service_community.service.ConvenientServiceCategoryService;
+
+/**
+ * @title: ConvenientServiceCategoryServiceImpl
+ * @projectName: 成都呐喊信息技术有限公司-智慧社区项目
+ * @description: 便民服务分类服务实现类
+ * @author: hans
+ * @date: 2021/09/16 10:56
+ */
+@Service
+public class ConvenientServiceCategoryServiceImpl extends ServiceImpl<ConvenientServiceCategoryDAO, ConvenientServiceCategoryDO>
+        implements ConvenientServiceCategoryService {
+
+    @Override
+    public R addServiceCategory(ConvenientServiceCategoryDTO convenientServiceCategoryDTO) {
+        ConvenientServiceCategoryDO convenientServiceCategoryDO = new ConvenientServiceCategoryDO();
+        BeanUtils.copyProperties(convenientServiceCategoryDTO, convenientServiceCategoryDO);
+        convenientServiceCategoryDO.setCreatedAt(new Date());
+        int result = this.baseMapper.insert(convenientServiceCategoryDO);
+        if (result > 0) {
+            return R.ok();
+        }
+        return R.fail("添加失败");
+    }
+
+    @Override
+    public R putServiceCategory(ConvenientServiceCategoryDTO convenientServiceCategoryDTO) {
+        ConvenientServiceCategoryDO convenientServiceCategoryDO = this.baseMapper.selectById(convenientServiceCategoryDTO.getId());
+        if (isNull(convenientServiceCategoryDO)) {
+            return R.fail("分类id不存在");
+        }
+        BeanUtils.copyProperties(convenientServiceCategoryDTO, convenientServiceCategoryDO);
+        int result = this.baseMapper.updateById(convenientServiceCategoryDO);
+        if (result > 0) {
+            return R.ok();
+        }
+        return R.fail("更新失败");
+    }
+
+    @Override
+    public R deleteServiceCategoryById(Long categoryId, Long operator) {
+        if (isNull(categoryId)) {
+            return R.fail("分类id不能为空");
+        }
+        ConvenientServiceCategoryDO convenientServiceCategoryDO = this.baseMapper.selectById(categoryId);
+        if (isNull(convenientServiceCategoryDO)) {
+            return R.fail("分类id不存在");
+        }
+        int count = this.baseMapper.checkCategoryIsUsing(categoryId);
+        if (count > 0) {
+            return R.fail("分类已被引用,无法删除");
+        }
+        convenientServiceCategoryDO.setIsDel(true);
+        convenientServiceCategoryDO.setUpdatedBy(operator);
+        int result = this.baseMapper.updateById(convenientServiceCategoryDO);
+        if (result > 0) {
+            return R.ok();
+        }
+        return R.fail("删除失败");
+    }
+
+    @Override
+    public R getServiceCategoryById(Long categoryId) {
+        if (isNull(categoryId)) {
+            return R.fail("分类id不能为空");
+        }
+        ConvenientServiceCategoryDO convenientServiceCategoryDO = this.baseMapper.selectById(categoryId);
+        if (isNull(convenientServiceCategoryDO)) {
+            return R.fail("分类id不存在");
+        }
+        ConvenientServiceCategoryVO convenientServiceCategoryVO = new ConvenientServiceCategoryVO();
+        BeanUtils.copyProperties(convenientServiceCategoryDO, convenientServiceCategoryVO);
+        return R.ok(convenientServiceCategoryVO);
+    }
+
+    @Override
+    public R pageServiceCategory(PageConvenientServiceCategoryDTO pageConvenientServiceCategoryDTO) {
+        Page page = new Page<>();
+        page.setSize(pageConvenientServiceCategoryDTO.getPageSize());
+        page.setCurrent(pageConvenientServiceCategoryDTO.getPageNum());
+        IPage<ConvenientServiceCategoryVO> iPage = this.baseMapper.pageServiceCategory(page, pageConvenientServiceCategoryDTO);
+        return R.ok(iPage);
+    }
+
+    @Override
+    public R getAllServiceCategories() {
+        List<ConvenientServiceCategoryVO> categoryVOList = new ArrayList<>();
+        List<ConvenientServiceCategoryDO> categoryDOS = this.baseMapper.selectList(new QueryWrapper<ConvenientServiceCategoryDO>()
+                .lambda().orderByDesc(ConvenientServiceCategoryDO::getWeight));
+        if (!ObjectUtils.isEmpty(categoryDOS)) {
+            categoryDOS.forEach(categoryDO -> {
+                ConvenientServiceCategoryVO categoryVO = new ConvenientServiceCategoryVO();
+                BeanUtils.copyProperties(categoryDO, categoryVO);
+                categoryVOList.add(categoryVO);
+            });
+        }
+        return R.ok(categoryVOList);
+    }
+
+    @Override
+    public R getSuitableServiceCategories(Long communityId) {
+        return R.ok(this.baseMapper.selectSuitableServiceCategories(communityId));
+    }
+}

--
Gitblit v1.7.1