| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411 |
- package me.zhengjie.archives.service.impl;
- import java.io.File;
- import java.time.LocalDate;
- import java.time.LocalDateTime;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import java.util.stream.Collectors;
- import org.apache.commons.collections4.CollectionUtils;
- import org.apache.commons.lang.StringUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import org.springframework.web.bind.annotation.RequestBody;
- import com.alibaba.fastjson.JSON;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
- import com.baomidou.mybatisplus.core.metadata.IPage;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import me.zhengjie.annotation.rest.AnonymousPostMapping;
- import me.zhengjie.archives.dao.IGzArchivesDao;
- import me.zhengjie.archives.dao.IModelDao;
- import me.zhengjie.archives.dto.GzDetailDto;
- import me.zhengjie.archives.entity.ArchivesEntity;
- import me.zhengjie.archives.entity.FileInfoEntity;
- import me.zhengjie.archives.entity.GzArchivesEntity;
- import me.zhengjie.archives.entity.GzArchivesExEntity;
- import me.zhengjie.archives.entity.GzDetailEntity;
- import me.zhengjie.archives.entity.GzFileTempEntity;
- import me.zhengjie.archives.entity.GzFilepathEntity;
- import me.zhengjie.archives.entity.ModelEntity;
- import me.zhengjie.archives.plus.AbstractServiceImpl;
- import me.zhengjie.archives.plus.QueryMap;
- import me.zhengjie.archives.service.FileInfoService;
- import me.zhengjie.archives.service.GzArchivesExService;
- import me.zhengjie.archives.service.GzArchivesService;
- import me.zhengjie.archives.service.GzDetailService;
- import me.zhengjie.archives.service.GzFileTempService;
- import me.zhengjie.archives.service.GzFilepathService;
- import me.zhengjie.archives.util.HtmlToImage;
- import me.zhengjie.archives.util.PdfUtils;
- import me.zhengjie.archives.vo.GzArchivesVo;
- import me.zhengjie.archives.vo.GzPortraitVo;
- import me.zhengjie.base.ResponseDTO;
- import me.zhengjie.config.FileProperties;
- import me.zhengjie.exception.BadRequestException;
- import me.zhengjie.modules.system.service.DictDetailService;
- import me.zhengjie.utils.DateUtil;
- import me.zhengjie.utils.FileUtil;
- import me.zhengjie.utils.PageUtil;
- import me.zhengjie.utils.UUIDGenerator;
- /**
- * <p>
- * 服务实现类
- * </p>
- *
- * @author <a href="https://www.fengwenyi.com?code">Erwin Feng</a>
- * @since 2023-06-25
- */
- @Service
- public class GzArchivesServiceImpl extends AbstractServiceImpl<IGzArchivesDao, GzArchivesEntity>
- implements GzArchivesService {
- @Autowired
- DictDetailService dictDetailService;
- @Autowired
- IModelDao modelDao;
- @Autowired
- private FileProperties properties;
- @Autowired
- FileInfoService fileInfoService;
- @Autowired
- private GzFileTempService gzFileTempService;
- @Autowired
- GzArchivesExService gzArchivesExService;
- @Autowired
- private GzDetailService gzDetailService;
- @Autowired
- private GzFilepathService gzFilepathService;
- public void mergeSubmit(GzPortraitVo archives) throws Exception {
- image(archives);
- }
- public void image(GzPortraitVo archives) throws Exception {
- String path = properties.getPath().getPath();
- // 查询对应的值
- GzArchivesEntity entity = this.getById(archives.getId());
- // 保管期限
- String saveTerm = dictDetailService.getLabelByValue("saveTerm_type", entity.getKeepingterm());
- // 卷宗号
- String dossierNum = entity.getYear() + "-" + entity.getNotarizationtypefull() + "-" + saveTerm + "-"
- + entity.getFileno();
- // TODO 当事人很多,需要修改字体-------------------页号开始------------------------
- QueryWrapper<ModelEntity> queryWrapper = new QueryWrapper<ModelEntity>();
- queryWrapper.eq("code", 1);
- ModelEntity model = modelDao.selectOne(queryWrapper);
- String fileRelatePath = FileUtil.getUploadPath(path);
- String filePath = path + fileRelatePath;
- String headPageHtml = model.getContent();
- // 替换内容
- headPageHtml = headPageHtml.replace("${year}", entity.getYear().toString())
- .replace("${notarialNum}", entity.getNo()).replace("${notarizedItem}", entity.getTitle())
- .replace("${partyName}", entity.getConcernedname()).replace("${undertaker}", entity.getUndertaker())
- .replace("${notary}", entity.getNotary())
- .replace("${acceptDate}", DateUtil.localDate(entity.getAcceptdate()))
- .replace("${completeDate}", DateUtil.localDate(entity.getFinishdate()))
- .replace("${filingDate}", DateUtil.localDate(entity.getFiledate())).replace("${saveTerm}", saveTerm)
- .replace("${dossierNum}", dossierNum).replace("${acceptNum}", entity.getAcceptno())
- .replace("${fondsNum}", entity.getFondcode()).replace("${catalogNum}", entity.getMenuno())
- .replace("${caseNum}", entity.getFileno());
- String headPagePath = filePath + UUIDGenerator.uuid() + ".html";
- String headPageToImage = filePath + UUIDGenerator.uuid() + ".jpg";
- // 先写入文本
- FileUtil.writeUtf8String(headPageHtml, headPagePath);
- // 然后生成jpg
- String exePath = dictDetailService.getValueByName("file_path").get("exe_path");
- HtmlToImage.htmlToImg(exePath, headPagePath, headPageToImage);
- FileUtil.deleteFile(new File(headPagePath));
- // -------------------页号结束------------------------
- // --------------------目录号开始---------
- queryWrapper = new QueryWrapper<ModelEntity>();
- queryWrapper.eq("code", 2);
- model = modelDao.selectOne(queryWrapper);
- String catalogHtml = model.getContent();
- int j = 0;
- List<String> pages = archives.getPages();
- for (int i = 0; i < pages.size(); i++) {
- j = i + 1;
- catalogHtml = catalogHtml.replace("${num" + j + "}", pages.get(i));
- }
- String catalogPath = filePath + UUIDGenerator.uuid() + ".html";
- String catalogToImage = filePath + UUIDGenerator.uuid() + ".jpg";
- // 先写入文本
- FileUtil.writeUtf8String(catalogHtml, catalogPath);
- // 然后生成jpg
- HtmlToImage.htmlToImg(exePath, catalogPath, catalogToImage);
- FileUtil.deleteFile(new File(catalogPath));
- List<File> files = new ArrayList<File>();
- // 页头第一个
- files.add(new File(headPageToImage));
- // 目录放在第二个
- files.add(new File(catalogToImage));
- List<String> imageIds = archives.getImageIds();
- // 区分是新增加的,还是老的数据,历史数据是32位,新的是22位
- List<String> fileInfoImages = new ArrayList<>();
- List<String> gzFileImages = new ArrayList<>();
- // 判断
- for (String imageId : imageIds) {
- if (imageId.length() == 32) {
- gzFileImages.add(imageId);
- } else {
- fileInfoImages.add(imageId);
- }
- }
- // 这个是新的图片地址
- Map<String, FileInfoEntity> fileInfoMap = new HashMap<>();
- if(CollectionUtils.isNotEmpty(fileInfoImages)) {
- List<FileInfoEntity> fileInfo = fileInfoService.listByIds(fileInfoImages);
- for (FileInfoEntity file : fileInfo) {
- fileInfoMap.put(file.getId(), file);
- }
- }
- // ------------------------这个是老的地址
- Map<String, GzFileTempEntity> tempFilesMap = new HashMap<>();
- if(CollectionUtils.isNotEmpty(gzFileImages)) {
- List<GzFileTempEntity> tempFiles = gzFileTempService.listByIds(gzFileImages);
- for (GzFileTempEntity file : tempFiles) {
- tempFilesMap.put(file.getId(), file);
- }
- }
-
- for (String imageId : imageIds) {
- if (imageId.length() == 32) {
- if(tempFilesMap.get(imageId)!=null) {
- GzFileTempEntity gzFileEntity = tempFilesMap.get(imageId);
- files.add(new File(gzFileEntity.getFilePath() + gzFileEntity.getFileName()));
- }
- } else {
- if(fileInfoMap.get(imageId)!=null) {
- files.add(new File(path + fileInfoMap.get(imageId).getPath()));
- }
-
- }
- }
- // --------------------------------------------------
- String fileName = "merge_pdf" + UUIDGenerator.uuid() + ".pdf";
- String toPdfTarget = filePath + fileName;
- // pdf进行合并
- PdfUtils.manyImageToOnePdf(files, toPdfTarget);
- // 先更新主表
- entity = new GzArchivesEntity();
- entity.setId(archives.getId());
- entity.setRecflag("1");
- entity.setPdftime(LocalDate.now());
- this.updateById(entity);
- // -------------------
- GzArchivesExEntity archiveEntity = new GzArchivesExEntity();
- archiveEntity.setGzArchivesId(archives.getId());
- GzArchivesExEntity gzEx = gzArchivesExService.getOne(archiveEntity);
- if (gzEx == null) {
- gzEx = new GzArchivesExEntity();
- gzEx.setPdfPath(fileRelatePath + fileName);
- gzEx.setGzArchivesId(archives.getId());
- gzEx.setImageJson(JSON.toJSONString(archives));
- gzEx.setCreateTime(LocalDateTime.now());
- gzEx.setUpdateTime(LocalDateTime.now());
- gzEx.setPdfPath(fileRelatePath+fileName);
- gzArchivesExService.save(gzEx);
- } else {
-
- gzEx.setGzArchivesId(archives.getId());
- gzEx.setPdfPath(fileRelatePath + fileName);
- gzEx.setImageJson(JSON.toJSONString(archives));
- gzEx.setPdfPath(fileRelatePath+fileName);
- gzEx.setUpdateTime(LocalDateTime.now());
- gzArchivesExService.updateById(gzEx);
- }
- UpdateWrapper<FileInfoEntity> updateWrapper = new UpdateWrapper<>();
- updateWrapper.in("id", imageIds);
- updateWrapper.set("loan_no", archives.getId());
- this.fileInfoService.update(updateWrapper);
- }
- @AnonymousPostMapping("/detail")
- public ResponseDTO<GzDetailDto> detail(GzArchivesVo req) {
- GzArchivesEntity entity = this.getById(req.getId());
- // GzArchivesDto dto = BeanCopyUtils.convertObj(entity, GzArchivesDto.class);
- GzDetailDto dto = new GzDetailDto();
- convertArchives(entity, dto);
- // 先查询有没有处理过,然后再处理老的数据
- GzArchivesExEntity gzExEntity = new GzArchivesExEntity();
- gzExEntity.setGzArchivesId(req.getId());
- gzExEntity = gzArchivesExService.getOne(gzExEntity);
- if (gzExEntity != null) {
- String previewPath = dictDetailService.getValueByName("file_path").get("preview_path");
- Map<String,String> pdfFileName = new HashMap<>();
- pdfFileName.put("pdfPath", previewPath + gzExEntity.getPdfPath());
- // 卷宗号
- pdfFileName.put("pdfName", entity.getArcno());
- List<Map<String,String>> pdfList=new ArrayList<>();
- pdfList.add(pdfFileName);
- dto.setFilePath(pdfList);
- return ResponseDTO.success(dto);
- }
- QueryWrapper<GzDetailEntity> qw = new QueryWrapper<>();
- qw.eq("puuid", req.getId());
- List<String> gzIds = gzDetailService.list(qw).stream().map(e -> e.getId()).collect(Collectors.toList());
- QueryWrapper<GzFilepathEntity> gzFilepathQw = new QueryWrapper<>();
- gzFilepathQw.in("puuid", gzIds);
- gzFilepathQw.orderByAsc(" arccode+0 ");
- String gzPath = dictDetailService.getValueByName("file_path").get("gz_path");
- List<GzFilepathEntity> gzFilePaths = gzFilepathService.list(gzFilepathQw);
- if (CollectionUtils.isNotEmpty(gzFilePaths)) {
- List<Map<String,String>> pdfs = new ArrayList<>();
- for (GzFilepathEntity gz : gzFilePaths) {
- //pdfs.add(gzPath + gz.getSubpath() + gz.getFilename() + gz.getExt());
- Map<String,String> pdfFileName = new HashMap<>();
- pdfFileName.put("pdfPath", gzPath + gz.getSubpath() + gz.getFilename() + gz.getExt());
- pdfFileName.put("pdfName", gz.getFilename());
- pdfs.add(pdfFileName);
- }
- dto.setFilePath(pdfs);
- return ResponseDTO.success(dto);
- }
- return ResponseDTO.success(dto);
- }
- public Map<String, Object> page(GzArchivesVo req) {
- IPage<GzArchivesEntity> page = new Page<>(req.getIndex() + 1, req.getSize());
- GzArchivesEntity gzArchives = new GzArchivesEntity();
- convertGz(gzArchives, req);
- QueryMap queryMap = new QueryMap();
- Map<String, Object> map = new HashMap<>();
- List<String> accept = req.getAcceptDates();
- if (CollectionUtils.isNotEmpty(accept)) {
- String stringDate = accept.get(0);
- map.put("startTime", stringDate);
- String endDate = accept.get(1);
- map.put("endTime", endDate);
- queryMap.setMap(map);
- }
- List<String> submitTime = req.getSubmitTimes();
- if (CollectionUtils.isNotEmpty(submitTime)) {
- map.put("submitStartTime", submitTime.get(0));
- map.put("submitEndTime", submitTime.get(1));
- queryMap.setMap(map);
- }
- page = page(page, gzArchives, queryMap);
- List<GzDetailDto> list = new ArrayList<>();
- if (page.getRecords() != null) {
- for (GzArchivesEntity gz : page.getRecords()) {
- GzDetailDto archivesEntity = new GzDetailDto();
- convertArchives(gz, archivesEntity);
- list.add(archivesEntity);
- }
- }
- return PageUtil.toPage(list, page.getTotal());
- }
- private void convertArchives(GzArchivesEntity gz, GzDetailDto archivesEntity) {
- StringBuffer sb = new StringBuffer();
- sb.append(gz.getYear() + "-");
- sb.append(gz.getNotarizationtypefull() + "-");
- sb.append(gz.getKeepingterm() + "-");
- sb.append(gz.getFileno());
- archivesEntity.setId(gz.getId());
- archivesEntity.setArchivesNum(gz.getArcno());
- archivesEntity.setDossierNum(sb.toString());
- archivesEntity.setNotarizationType(gz.getNotarialOfficeFull());
- archivesEntity.setNotarizedItem(gz.getTitle());
- archivesEntity.setNotarialNum(gz.getNotarizationnumber());
- archivesEntity.setNotary(gz.getNotary());
- archivesEntity.setUndertaker(gz.getUndertaker());
- archivesEntity.setPartyName(gz.getConcernedname());
- archivesEntity.setAcceptNum(gz.getAcceptno());
- archivesEntity.setAnnual(gz.getYear().toString());
- archivesEntity.setAcceptDate(DateUtil.formatYmd(gz.getAcceptdate()));
- archivesEntity.setCompleteDate(DateUtil.formatYmd(gz.getFinishdate()));
- archivesEntity.setFilingDate(DateUtil.formatYmd(gz.getFiledate()));
- archivesEntity.setSaveTerm(gz.getKeepingterm());
- archivesEntity.setSecrecyType(gz.getSecretclass());
- archivesEntity.setNotaryFullName(gz.getNotarialOfficeFull());
- archivesEntity.setCaseNum(gz.getFileno());
- archivesEntity.setStatus(gz.getRecflag());
- archivesEntity.setFondsNum(gz.getFondcode());
- archivesEntity.setCatalogNum(gz.getMenuno());
- archivesEntity.setBoxNum(gz.getBoxnumber());
- archivesEntity.setCreateTime(gz.getCreatetime());
- archivesEntity.setDossierType(gz.getMenuno().split("\\.")[1]);
- }
- public static void main(String[] args) {
- System.out.println("1.2".split("\\.")[1]);
- }
- public ResponseDTO<GzArchivesEntity> edit(@RequestBody GzArchivesVo req) {
- GzArchivesEntity entity = getById(req.getId());
- String arcno=entity.getArcno();
- convertGz(entity, req);
- QueryWrapper<GzArchivesEntity> qw = new QueryWrapper<>();
- qw.ne("arcno", arcno);
- qw.eq("arcno", req.getArchivesNum());
- long result = this.count(qw);
- // 过来掉自己
- if (result >= 1) {
- // return ResponseDTO.error(ResultCode.ARCHIVES_NUM_ALREADY_EXISTS,
- // archives.getArchivesNum());
- throw new BadRequestException(entity.getArcno() + "档案号已存在!");
- }
- this.updateById(entity);
-
- return ResponseDTO.success();
- }
- private void convertGz(GzArchivesEntity gz, GzArchivesVo archivesEntity) {
- // 目录号
- gz.setMenuno(archivesEntity.getCatalogNum());
- // caseNum 案卷号
- gz.setFileno(archivesEntity.getCaseNum());
- // 公证书编号
- gz.setNotarizationnumber(archivesEntity.getNotarialNum());
- // 当事人姓名
- gz.setConcernedname(archivesEntity.getPartyName());
- // 公证员
- gz.setNotary(archivesEntity.getNotary());
- // 承办人
- gz.setUndertaker(archivesEntity.getUndertaker());
- // 公证事项
- gz.setTitle(archivesEntity.getNotarizedItem());
- // 受理号
- gz.setAcceptno(archivesEntity.getAcceptNum());
- if (StringUtils.isNotBlank(archivesEntity.getAnnual())) {
- gz.setYear(Integer.parseInt(archivesEntity.getAnnual()));
- }
- // 年度
- gz.setArcno(archivesEntity.getArchivesNum());
- // 三个时间
- if (StringUtils.isNotBlank(archivesEntity.getAcceptDate())) {
- gz.setAcceptdate(DateUtil.parseYmd(archivesEntity.getAcceptDate()));
- }
- if (StringUtils.isNotBlank(archivesEntity.getCompleteDate())) {
- gz.setFinishdate(DateUtil.parseYmd(archivesEntity.getCompleteDate()));
- }
- if (StringUtils.isNotBlank(archivesEntity.getFilingDate())) {
- gz.setFiledate(DateUtil.parseYmd(archivesEntity.getFilingDate()));
- }
- //设置状态值
- gz.setRecflag(archivesEntity.getStatus());
- // 保管类型
- gz.setSecretclass(archivesEntity.getSecrecyType());
- // 保管期限
- gz.setKeepingterm(archivesEntity.getSaveTerm());
- // 将类型转成汉字
- String dossierType = dictDetailService.getLabelByValue("saveTerm_type", archivesEntity.getDossierType());
- gz.setNotarizationtypefull(dossierType);
- gz.setFondcode(archivesEntity.getFondsNum());
- gz.setBoxnumber(archivesEntity.getBoxNum());
- }
- }
|