package com.example.jz.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; 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.*; import com.example.jz.modle.PageParam; import com.example.jz.modle.dto.AddReportDto; import com.example.jz.modle.dto.CauseDto; import com.example.jz.modle.entity.*; import com.example.jz.modle.vo.AnnouncementVo; import com.example.jz.modle.vo.CauseReportVo; 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 org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; 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; @Resource GroupUserDao groupUserDao; @Resource AnnouncementDao announcementDao; @Override @Transactional(rollbackFor = Exception.class) 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()))); causeVo.setGroupId(groupDao.selectOne(new QueryWrapper().eq("cause_id", a.getId())).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); } @Override public List getReporterList(Integer causeId) { return reportDao.selectList(new QueryWrapper().eq("cause_id", causeId)).stream() .map( a -> { CauseReportVo causeReportVo = new CauseReportVo(); User user = userDao.selectOne(new QueryWrapper().eq("id", a.getUserId())); BeanUtils.copyProperties(a, causeReportVo); causeReportVo.setUserIdcard(user.getUserIdcard()); causeReportVo.setUserMobile(user.getUserMobile()); causeReportVo.setUserIdcard(causeReportVo.getUserIdcard().replaceAll("(?<=[\\d]{3})\\d(?=[\\d]{4})", "*")); causeReportVo.setUserName(user.getRealName()); return causeReportVo; } ).collect(Collectors.toList()); } @Override public List getGroupAnnouncement(Integer groupId) { return announcementDao.selectList(new QueryWrapper().eq("group_id", groupId)).stream() .map( a -> { AnnouncementVo announcementVo = new AnnouncementVo(); BeanUtils.copyProperties(a, announcementVo); return announcementVo; } ).collect(Collectors.toList()); } @Override public void deleteCause(Integer id) { causeDao.deleteById(id); } @Override @Transactional public Boolean addReportPeople(AddReportDto addReportDto) { User user = userDao.selectOne(new LambdaQueryWrapper(User.class).eq(User::getUserIdcard, addReportDto.getIdcard())); if (user == null) { // 如果用户不存在 则添加用户 user = new User().setUserIdcard(addReportDto.getIdcard()).setUserMobile(addReportDto.getMobile()).setRealName(addReportDto.getReporterName()) .setModifyTime(new Date()).setUserRegtime(new Date()).setPic(addReportDto.getPic()); userDao.insert(user); } // 添加人员进群组 groupUserDao.insert(new GroupUser().setGroupId(addReportDto.getGroupId()).setUserId(user.getId()).setCtime(new Date()).setBanSpeech(0)); // 添加报案信息 Report report = new Report(); BeanUtils.copyProperties(addReportDto, report); report .setUserId(user.getId()) .setCtime(new Date()) .setStatus(0) .setReportMethod("现场录入") .setIsCommission("0").setReportTime(new Date()) .setCauseId(groupDao.selectOne(new QueryWrapper().eq("id", addReportDto.getGroupId())).getCauseId()); return reportDao.insert(report) > 0; } }