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
package com.panzhihua.service_community.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.panzhihua.common.model.dtos.common.*;
import com.panzhihua.common.model.vos.R;
import com.panzhihua.service_community.dao.ComMngVolunteerMngDAO;
import com.panzhihua.service_community.dao.ComMngVolunteerSkillMapper;
import com.panzhihua.service_community.model.dos.ComMngVolunteerMngDO;
import com.panzhihua.service_community.model.dos.ComMngVolunteerSkill;
import com.panzhihua.service_community.service.ComMngVolunteerSkillService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.Date;
 
 
/**
 * 志愿者技能表(ComMngVolunteerSkill)表服务实现类
 *
 * @author lyq
 * @since 2021-10-30 16:47:37
 */
@Service("comMngVolunteerSkillService")
public class ComMngVolunteerSkillServiceImpl extends ServiceImpl<ComMngVolunteerSkillMapper, ComMngVolunteerSkill> implements ComMngVolunteerSkillService {
 
    @Resource
    private ComMngVolunteerMngDAO comMngVolunteerMngDAO;
 
 
    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public R queryById(Long id) {
        return R.ok(this.baseMapper.queryById(id));
    }
 
    /**
     * 分页查询
     *
     * @param comMngVolunteerSkill 筛选条件
     * @return 查询结果
     */
    @Override
    public R queryByPage(PageComMngVolunteerSkillDto comMngVolunteerSkill) {
        return R.ok(this.baseMapper.queryAllByLimit(comMngVolunteerSkill,new Page(comMngVolunteerSkill.getPageNum(), comMngVolunteerSkill.getPageSize())));
    }
 
    /**
     * 新增数据
     *
     * @param comMngVolunteerSkill 实例对象
     * @return 实例对象
     */
    @Override
    public R insert(AddComMngVolunteerSkillDto comMngVolunteerSkill) {
        ComMngVolunteerSkill entity = new ComMngVolunteerSkill();
        BeanUtils.copyProperties(comMngVolunteerSkill, entity);
        entity.setCreateBy(comMngVolunteerSkill.getUserId());
        entity.setCreateAt(new Date());
        if (this.baseMapper.insert(entity) > 0) {
            return R.ok();
        }
        return R.fail("添加失败");
    }
 
    /**
     * 修改数据
     *
     * @param editDto 实例对象
     * @return 实例对象
     */
    @Override
    public R update(EditComMngVolunteerSkillDto editDto) {
        ComMngVolunteerSkill entity = this.baseMapper.selectById(editDto.getId());
        if (entity == null) {
            return R.fail("未查询到该记录");
        }
        BeanUtils.copyProperties(editDto, entity);
        entity.setUpdateAt(new Date());
        entity.setUpdateBy(editDto.getUserId());
        if (this.baseMapper.updateById(entity) > 0) {
            return R.ok();
        }
        return R.fail("修改失败");
    }
 
    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public R deleteById(Long id) {
        Integer count = comMngVolunteerMngDAO.selectCount(new QueryWrapper<ComMngVolunteerMngDO>().lambda()
                .eq(ComMngVolunteerMngDO::getSkillId,id).ne(ComMngVolunteerMngDO::getState,3));
        if(count > 0){
            return R.fail("该技能已被引用,无法删除!");
        }
        if (this.baseMapper.deleteById(id) > 0) {
            return R.ok();
        }
        return R.fail("删除失败");
    }
 
    /**
     * 社区后台-查询志愿者技能列表
     * @param comMngVolunteerSkill 请求参数
     * @return  志愿者技能列表
     */
    @Override
    public R queryByList(PageComMngVolunteerSkillDto comMngVolunteerSkill){
        return R.ok(this.baseMapper.queryAll(comMngVolunteerSkill));
    }
}