mitao
2025-02-21 31573d6180d15ef65ed0df9c2732495f40b12663
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
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(String areaCode) {
        List<ConvenientServiceCategoryVO> categoryVOList = new ArrayList<>();
        List<ConvenientServiceCategoryDO> categoryDOS = this.baseMapper.selectList(new QueryWrapper<ConvenientServiceCategoryDO>()
                .lambda().eq(ConvenientServiceCategoryDO::getAreaCode,areaCode).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,String areaCode) {
        return R.ok(this.baseMapper.selectSuitableServiceCategories(communityId,areaCode));
    }
}