| | |
| | | package com.example.jz.service.impl; |
| | | |
| | | import com.alibaba.excel.EasyExcel; |
| | | import com.alibaba.excel.context.AnalysisContext; |
| | | import com.alibaba.excel.event.AnalysisEventListener; |
| | | import com.alibaba.excel.metadata.data.ImageData; |
| | | import com.alibaba.excel.metadata.data.WriteCellData; |
| | | import com.alibaba.excel.support.ExcelTypeEnum; |
| | | import com.alibaba.excel.util.IoUtils; |
| | | import com.alibaba.excel.util.StringUtils; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | 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.example.jz.dao.GroupDao; |
| | | import com.example.jz.dao.GroupUserDao; |
| | | import com.example.jz.dao.ReportDao; |
| | | import com.example.jz.dao.UserDao; |
| | | import com.example.jz.modle.dto.AddReportDto; |
| | | import com.example.jz.modle.dto.ReportParamDto; |
| | | import com.example.jz.modle.entity.Group; |
| | | import com.example.jz.modle.entity.GroupUser; |
| | | import com.example.jz.modle.entity.Report; |
| | | import com.example.jz.modle.entity.User; |
| | | import com.example.jz.modle.vo.ReportListVo; |
| | | import com.example.jz.dao.*; |
| | | import com.example.jz.modle.PageParam; |
| | | import com.example.jz.modle.dto.AddReportDto; |
| | | import com.example.jz.modle.dto.AddReportLoadDto; |
| | | import com.example.jz.modle.dto.ReportParamDto; |
| | | import com.example.jz.modle.entity.*; |
| | | import com.example.jz.modle.vo.ExportExcelReportVo; |
| | | import com.example.jz.modle.vo.ReportListVo; |
| | | import com.example.jz.modle.vo.ReportVXVO; |
| | | import com.example.jz.service.MinIOService; |
| | | import com.example.jz.service.ReportService; |
| | | import com.example.jz.service.UserService; |
| | | import lombok.SneakyThrows; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.security.core.context.SecurityContextHolder; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.Serializable; |
| | | import java.net.URL; |
| | | import java.net.URLEncoder; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.ArrayList; |
| | | import java.io.Serializable; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.function.Consumer; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 报案表(Report)表服务实现类 |
| | |
| | | |
| | | @Resource |
| | | UserDao userDao; |
| | | @Resource |
| | | UserService userService; |
| | | @Resource |
| | | ReportService reportService; |
| | | |
| | | @Resource |
| | | MinIOService minIOService; |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Boolean audit(Report report) { |
| | | // 1. 更新报案表 |
| | | report.setStatus(1); |
| | | report.setIsInGroup(1); |
| | | reportDao.updateById(report); |
| | | // 2. 更新群用户表 |
| | | Group group = groupDao.selectOne(new LambdaQueryWrapper<>(Group.class) |
| | | .eq(Group::getCauseId, report.getCauseId())); |
| | | GroupUser groupUser = new GroupUser().setGroupId(group.getId()).setUserId(report.getUserId()).setCtime(new Date()).setBanSpeech(0); |
| | | groupUserDao.insert(groupUser); |
| | | if (!groupUserDao.selectUserList(group.getId()).contains(report.getUserId())) { |
| | | GroupUser groupUser = new GroupUser().setGroupId(group.getId()).setUserId(report.getId()).setCtime(new Date()).setBanSpeech(0); |
| | | return groupUserDao.insert(groupUser) == 1 ? true : false; |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | @Override |
| | | public void leaveGroup(Integer id, Integer groupId) { |
| | | Report report = new Report(); |
| | | report.setIsInGroup(0); |
| | | report.setId(id); |
| | | reportDao.updateById(report); |
| | | groupUserDao.delete(new QueryWrapper<GroupUser>().eq("user_id", id).eq("group_id", groupId)); |
| | | } |
| | | |
| | | @Override |
| | | @SneakyThrows |
| | | public void exportReporter(Integer id, HttpServletResponse response) { |
| | | //查询报案人相关信息通过案件 |
| | | List<Report> reports = reportDao.selectList(new QueryWrapper<Report>().eq("cause_id", id).orderByDesc()); |
| | | ArrayList<ExportExcelReportVo> exportExcelReportVos = new ArrayList<>(); |
| | | reports.forEach( |
| | | a -> { |
| | | ExportExcelReportVo exportExcelReportVo = new ExportExcelReportVo(); |
| | | User user = userDao.selectOne(new QueryWrapper<User>().eq("id", a.getUserId())); |
| | | BeanUtils.copyProperties(a, exportExcelReportVo); |
| | | exportExcelReportVo.setUserIdcard(user.getUserIdcard()); |
| | | exportExcelReportVo.setUserMobile(user.getUserMobile()); |
| | | exportExcelReportVo.setRealName(user.getRealName()); |
| | | WriteCellData<List<ImageData>> objectWriteCellData = new WriteCellData<>(); |
| | | ArrayList<ImageData> imageDataList = new ArrayList<>(); |
| | | if (StringUtils.isNotBlank(a.getReportMaterials())) { |
| | | String[] urls = a.getReportMaterials().split(","); |
| | | for (int i = 0; i < urls.length; i++) { |
| | | int width=600; |
| | | try { |
| | | ImageData imageData = new ImageData(); |
| | | imageData.setImage(IoUtils.toByteArray(new URL(minIOService.getPreviewFileUrl(urls[i])).openConnection().getInputStream())); |
| | | imageData.setLeft(width/ urls.length*i); |
| | | imageData.setRight(width-width/ urls.length*(i+1)); |
| | | imageDataList.add(imageData); |
| | | } catch (Exception e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | } |
| | | } |
| | | objectWriteCellData.setImageDataList(imageDataList); |
| | | exportExcelReportVo.setWriteCellData(objectWriteCellData); |
| | | exportExcelReportVos.add(exportExcelReportVo); |
| | | } |
| | | ); |
| | | String name = causeDao.selectOne(new QueryWrapper<Cause>().eq("id", id)).getName(); |
| | | response.setHeader("Content-disposition", "attachment;filename="+ LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))+URLEncoder.encode(name+".xlsx","utf-8")); |
| | | response.setCharacterEncoding("utf-8"); |
| | | response.setContentType("application/vnd.ms-excel"); |
| | | EasyExcel.write(response.getOutputStream(), ExportExcelReportVo.class).sheet("材料导出").doWrite(exportExcelReportVos); |
| | | } |
| | | // @Override |
| | | // @SneakyThrows |
| | | // public void exportReporter(Integer id, HttpServletResponse response) { |
| | | // //查询报案人相关信息通过案件 |
| | | // List<Report> reports = reportDao.selectList(new QueryWrapper<Report>().eq("cause_id", id).orderByDesc()); |
| | | // ArrayList<ExportExcelReportVo> exportExcelReportVos = new ArrayList<>(); |
| | | // reports.forEach( |
| | | // new Consumer<Report>() { |
| | | // @Override |
| | | // public void accept(Report a) { |
| | | // ExportExcelReportVo exportExcelReportVo = new ExportExcelReportVo(); |
| | | // User user = userDao.selectOne(new QueryWrapper<User>().eq("id", a.getUserId())); |
| | | // BeanUtils.copyProperties(a, exportExcelReportVo); |
| | | // exportExcelReportVo.setUserIdcard(user.getUserIdcard()); |
| | | // exportExcelReportVo.setUserMobile(user.getUserMobile()); |
| | | // exportExcelReportVo.setRealName(user.getRealName()); |
| | | // WriteCellData<List<ImageData>> objectWriteCellData = new WriteCellData<>(); |
| | | // ArrayList<ImageData> imageDataList = new ArrayList<>(); |
| | | // if (StringUtils.isNotBlank(a.getReportMaterials())) { |
| | | // String[] urls = a.getReportMaterials().split(","); |
| | | // if (urls.length == 1) { |
| | | // int width = 600; |
| | | // try { |
| | | // ImageData imageData = new ImageData(); |
| | | // imageData.setImage(IoUtils.toByteArray(new URL(minIOService.getPreviewFileUrl(urls[0])).openConnection().getInputStream())); |
| | | // imageData.setRight(width / 2); |
| | | // imageDataList.add(imageData); |
| | | // } catch (Exception e) { |
| | | // throw new RuntimeException(e); |
| | | // } |
| | | // } else { |
| | | // for (int i = 0; i < urls.length; i++) { |
| | | // int width = 600; |
| | | // try { |
| | | // ImageData imageData = new ImageData(); |
| | | // imageData.setImage(IoUtils.toByteArray(new URL(minIOService.getPreviewFileUrl(urls[i])).openConnection().getInputStream())); |
| | | // imageData.setLeft(width / urls.length * i); |
| | | // imageData.setRight(width - width / urls.length * (i + 1)); |
| | | // imageDataList.add(imageData); |
| | | // } catch (Exception e) { |
| | | // throw new RuntimeException(e); |
| | | // } |
| | | // } |
| | | // } |
| | | // } |
| | | // objectWriteCellData.setImageDataList(imageDataList); |
| | | // exportExcelReportVo.setWriteCellData(objectWriteCellData); |
| | | // exportExcelReportVos.add(exportExcelReportVo); |
| | | // } |
| | | // } |
| | | // ); |
| | | // String name = causeDao.selectOne(new QueryWrapper<Cause>().eq("id", id)).getName(); |
| | | // response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); |
| | | // response.setCharacterEncoding("utf-8"); |
| | | // response.setHeader("Content-disposition", "attachment;filename=" + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + URLEncoder.encode(name + ".xlsx", "utf-8")); |
| | | // EasyExcel.write(response.getOutputStream(), ExportExcelReportVo.class).sheet("材料导出").doWrite(exportExcelReportVos); |
| | | // } |
| | | |
| | | @Override |
| | | public Page<ReportListVo> getPage(Page<ReportListVo> page, ReportParamDto reportParamDto) { |
| | | Page<ReportListVo> aaa = reportDao.getPage(page, reportParamDto); |
| | | aaa.getRecords().stream().forEach(x -> x.setIdcard(x.getIdcard().replaceAll("(?<=[\\d]{3})\\d(?=[\\d]{4})", "*"))); |
| | | return aaa; |
| | | return reportDao.getPage(page, reportParamDto); |
| | | } |
| | | |
| | | @Override |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Page<ReportListVo> getPageByGroupId(Page<ReportListVo> page, ReportParamDto reportParamDto, Integer groupId) { |
| | | Page<ReportListVo> aaa = reportDao.getPageByGroupId(page, reportParamDto,groupId); |
| | | public Page<ReportListVo> getPageByGroupId(Page<ReportListVo> page, ReportParamDto reportParamDto, Integer causeId) { |
| | | Long size = (page.getCurrent() - 1) * page.getSize(); |
| | | Long current = page.getSize(); |
| | | Page<ReportListVo> aaa = new PageParam<>(); |
| | | List<ReportListVo> list = reportDao.getPageByGroupId(reportParamDto, causeId, size, current); |
| | | list.forEach(item -> { |
| | | if (item.getIsInGroup() == 1) { |
| | | item.setGroupId(groupDao.selectOne(new QueryWrapper<Group>().eq("cause_id", causeId)).getId()); |
| | | } |
| | | }); |
| | | aaa.setRecords(list); |
| | | Integer pageByGroupIdCount = reportDao.getPageByGroupIdCount(reportParamDto, causeId); |
| | | aaa.setTotal(pageByGroupIdCount); |
| | | aaa.getRecords().stream().forEach(x -> x.setIdcard(x.getIdcard().replaceAll("(?<=[\\d]{3})\\d(?=[\\d]{4})", "*"))); |
| | | return aaa; |
| | | } |
| | |
| | | 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); |
| | | .setModifyTime(new Date()).setUserRegtime(new Date()).setPic(addReportDto.getPic()).setCtime(new Date()); |
| | | userService.save(user); |
| | | } |
| | | // 添加人员进群组 |
| | | // groupUserDao.insert(new GroupUser() |
| | | // .setGroupId(groupDao.selectOne(new QueryWrapper<Group>().eq("cause_id", addReportDto.getCauseId())).getId()) |
| | | // .setUserId(user.getId()).setCtime(new Date()) |
| | | // .setBanSpeech(0)); |
| | | // 添加报案信息 |
| | | Report report = new Report(); |
| | | BeanUtils.copyProperties(addReportDto, report); |
| | | report |
| | | .setCreator(userDao.selectOne(new QueryWrapper<User>().eq("login_username", SecurityContextHolder.getContext().getAuthentication().getPrincipal())).getId()) |
| | | .setUserId(user.getId()) |
| | | .setCtime(new Date()) |
| | | .setStatus(0) |
| | | .setReportMethod("现场录入") |
| | | .setIsCommission("0").setReportTime(new Date()); |
| | | return reportDao.insert(report) > 0; |
| | | .setIsInGroup(0) |
| | | .setReportMethod("现场报案") |
| | | .setIsCommission("0") |
| | | .setReportTime(new Date()) |
| | | .setCauseId(addReportDto.getCauseId()); |
| | | return reportService.save(report); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public List<Report> listGroup(Integer id) { |
| | | return reportDao.selectListGroup(id); |
| | | } |
| | | |
| | | @Override |
| | | @SneakyThrows |
| | | public void loadFileReport(MultipartFile multipartFile, Integer causeId) { |
| | | EasyExcel.read(multipartFile.getInputStream(), AddReportLoadDto.class, new AnalysisEventListener<AddReportLoadDto>() { |
| | | @Override |
| | | public void invoke(AddReportLoadDto data, AnalysisContext context) { |
| | | if (com.baomidou.mybatisplus.core.toolkit.StringUtils.isNotBlank(data.getReporterName()) && com.baomidou.mybatisplus.core.toolkit.StringUtils.isNotBlank(data.getIdcard())) { |
| | | AddReportDto addReportDto = new AddReportDto(); |
| | | BeanUtils.copyProperties(data, addReportDto); |
| | | addReportDto.setCauseId(causeId); |
| | | addReport(addReportDto); |
| | | } |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void doAfterAllAnalysed(AnalysisContext context) { |
| | | |
| | | } |
| | | }) |
| | | .autoCloseStream(true) |
| | | .doReadAll(); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Boolean reject(Integer id, String reason) { |
| | | Report report = reportDao.selectReportByReportId(id); |
| | | // 1. 更新报案表 |
| | | report.setStatus(2); |
| | | report.setIsInGroup(2); |
| | | report.setRemarks(reason); |
| | | reportDao.updateById(report); |
| | | return true; |
| | | } |
| | | |
| | | @Override |
| | | public ReportVXVO getRejectReportById(Integer id) { |
| | | ReportVXVO reportVXVO = new ReportVXVO(); |
| | | Report report = reportDao.selectOne(new LambdaQueryWrapper<Report>().eq(Report::getId, id)); |
| | | User user = userDao.selectOne(new LambdaQueryWrapper<User>().eq(User::getId, report.getUserId())); |
| | | BeanUtils.copyProperties(report, reportVXVO); |
| | | reportVXVO.setLocation(user.getLocation()); |
| | | reportVXVO.setWorkingLocation(user.getWorkingLocation()); |
| | | reportVXVO.setSex(user.getSex()); |
| | | reportVXVO.setRealName(user.getRealName()); |
| | | reportVXVO.setUserIdCard(user.getUserIdcard()); |
| | | return reportVXVO; |
| | | } |
| | | } |