package com.example.jz.service.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.example.jz.dao.CauseDao; import com.example.jz.dao.GroupDao; import com.example.jz.dao.ReportDao; import com.example.jz.dao.UserDao; import com.example.jz.modle.PageParam; import com.example.jz.modle.dto.CauseDto; import com.example.jz.modle.entity.Cause; import com.example.jz.modle.entity.Group; import com.example.jz.modle.entity.Report; import com.example.jz.modle.entity.User; import com.example.jz.modle.vo.CauseVo; import com.example.jz.modle.vo.UserVo; import com.example.jz.service.CauseService; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.stream.Collectors; /** * 案件表(Cause)表服务实现类 * * @author makejava * @since 2022-07-13 11:52:58 */ @Service("causeService") public class CauseServiceImpl extends ServiceImpl implements CauseService { @Resource CauseDao causeDao; @Resource UserDao userDao; @Resource ReportDao reportDao; @Resource CauseService causeService; @Resource GroupDao groupDao; @Override public Integer addCause(CauseDto causeDto) { //创建案件 Cause cause = new Cause(); BeanUtils.copyProperties(causeDto, cause); cause.setCtime(new Date()); causeService.save(cause); //创建群组 Group group = new Group(); group.setCtime(new Date()); group.setGroupName(causeDto.getName()); group.setUserId(causeDto.getUserId()); group.setCauseId(cause.getId()); return groupDao.insert(group); } @Override public PageParam getCauserListByCondition(String cause, Integer status, Integer size, Integer current) { QueryWrapper causeQueryWrapper = new QueryWrapper<>(); if (StringUtils.isNotBlank(cause)) { causeQueryWrapper.and(a -> a.like(StringUtils.isNotBlank(cause), "number", cause) .or(StringUtils.isNotBlank(cause)) .like(StringUtils.isNotBlank(cause), "name", cause)); } if (status != null) { causeQueryWrapper.eq("status", status); } causeQueryWrapper.orderByDesc("ctime"); PageParam causePageParam = new PageParam<>(); if (size != null) { causePageParam.setSize(size); } if (current != null) { causePageParam.setCurrent(current); } PageParam causePage = causeDao.selectPage(causePageParam, causeQueryWrapper); List causeVos = causePage.getRecords().stream().map( a -> { CauseVo causeVo = new CauseVo(); BeanUtils.copyProperties(a, causeVo); causeVo.setUserName(userDao.selectOne(new QueryWrapper().eq("id", a.getUserId())).getRealName()); causeVo.setReportNumber(reportDao.selectCount(new QueryWrapper().eq("cause_id", a.getId()))); return causeVo; }).collect(Collectors.toList()); PageParam causeVoPageParam = new PageParam<>(); BeanUtils.copyProperties(causePage, causeVoPageParam); causeVoPageParam.setRecords(causeVos); return causeVoPageParam; } @Override public List getManagerList() { return userDao.selectList(new QueryWrapper().eq("role", 1)).stream().map(a -> { UserVo userVo = new UserVo(); userVo.setUserId(a.getId()); userVo.setUserName(a.getRealName()); return userVo; }).collect(Collectors.toList()); } @Override public Integer updateCause(CauseDto causeDto,Integer id) { Cause cause = new Cause(); BeanUtils.copyProperties(causeDto,cause); cause.setId(id); return causeDao.updateById(cause); } }