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));
|
}
|
}
|