| | |
| | | package com.example.jz.service.impl; |
| | | |
| | | import com.alibaba.excel.EasyExcel; |
| | | 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.CauseDao; |
| | | import com.example.jz.dao.GroupDao; |
| | | import com.example.jz.dao.GroupUserDao; |
| | | import com.example.jz.dao.ReportDao; |
| | | 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.vo.ReportListVo; |
| | | import com.example.jz.dao.*; |
| | | import com.example.jz.modle.entity.*; |
| | | import com.example.jz.modle.vo.ExportExcelReportVo; |
| | | import com.example.jz.service.MinIOService; |
| | | import com.example.jz.service.ReportService; |
| | | import lombok.SneakyThrows; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | 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; |
| | | |
| | | /** |
| | | * 报案表(Report)表服务实现类 |
| | |
| | | private GroupDao groupDao; |
| | | @Autowired |
| | | private GroupUserDao groupUserDao; |
| | | |
| | | @Resource |
| | | CauseDao causeDao; |
| | | |
| | | @Resource |
| | | UserDao userDao; |
| | | |
| | | @Resource |
| | | MinIOService minIOService; |
| | | |
| | | /** |
| | | * 审核报案 |
| | |
| | | groupUserDao.insert(groupUser); |
| | | return true; |
| | | } |
| | | |
| | | @Override |
| | | public void leaveGroup(Integer id, Integer groupId) { |
| | | 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 |
| | | 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; |
| | | } |
| | | |
| | | @Override |
| | | public ReportListVo getReportListVoById(Serializable id) { |
| | | return reportDao.getReportListVoById(id); |
| | | } |
| | | |
| | | @Override |
| | | public Page<ReportListVo> getPageByGroupId(Page<ReportListVo> page, ReportParamDto reportParamDto, Integer groupId) { |
| | | Page<ReportListVo> aaa = reportDao.getPageByGroupId(page, reportParamDto,groupId); |
| | | aaa.getRecords().stream().forEach(x -> x.setIdcard(x.getIdcard().replaceAll("(?<=[\\d]{3})\\d(?=[\\d]{4})", "*"))); |
| | | return aaa; |
| | | } |
| | | } |
| | | |