|
|
@@ -3,30 +3,62 @@ package com.xunmei.core.letter.service.impl;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.alibaba.fastjson2.JSON;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.xunmei.common.core.constant.CacheConstants;
|
|
|
+import com.xunmei.common.core.constant.DictConstants;
|
|
|
import com.xunmei.common.core.constant.ErrorMsgConstants;
|
|
|
import com.xunmei.common.core.constant.SecurityConstants;
|
|
|
+import com.xunmei.common.core.domain.R;
|
|
|
+import com.xunmei.common.core.domain.edu.domain.CoreEduTrainingTask;
|
|
|
+import com.xunmei.common.core.domain.edu.domain.CoreEduTrainingTaskToUser;
|
|
|
+import com.xunmei.common.core.domain.edu.vo.CoreEduTrainingTaskDetailVo;
|
|
|
+import com.xunmei.common.core.domain.letter.domain.CoreIntroduceLetter;
|
|
|
+import com.xunmei.common.core.domain.letter.domain.CoreIntroduceLetterApproveLog;
|
|
|
+import com.xunmei.common.core.domain.letter.domain.CoreIntroduceLetterUser;
|
|
|
import com.xunmei.common.core.domain.letter.domain.CoreOutInRecord;
|
|
|
import com.xunmei.common.core.domain.letter.dto.CoreOutInRecordRequestDto;
|
|
|
import com.xunmei.common.core.domain.letter.vo.CoreOutInRecordVo;
|
|
|
+import com.xunmei.common.core.domain.registerbook.domain.CoreRegisterBookPdf;
|
|
|
+import com.xunmei.common.core.enums.RegisterBookType;
|
|
|
+import com.xunmei.common.core.exception.SystemException;
|
|
|
import com.xunmei.common.core.utils.DateUtils;
|
|
|
+import com.xunmei.common.core.web.domain.AjaxResult;
|
|
|
import com.xunmei.common.core.web.page.TableDataInfo;
|
|
|
+import com.xunmei.common.redis.utils.RedisUtils;
|
|
|
+import com.xunmei.common.security.utils.DictUtils;
|
|
|
import com.xunmei.common.security.utils.SecurityUtils;
|
|
|
+import com.xunmei.core.letter.mapper.CoreIntroduceLetterApproveLogMapper;
|
|
|
+import com.xunmei.core.letter.mapper.CoreIntroduceLetterMapper;
|
|
|
+import com.xunmei.core.letter.mapper.CoreIntroduceLetterUserMapper;
|
|
|
import com.xunmei.core.letter.mapper.CoreOutInRecordMapper;
|
|
|
import com.xunmei.core.letter.service.ICoreOutInRecordService;
|
|
|
|
|
|
+import com.xunmei.core.registerbook.service.ICoreRegisterBookPdfService;
|
|
|
+import com.xunmei.core.thread.ThreadPoolConfig;
|
|
|
+import com.xunmei.system.api.RemoteFileService;
|
|
|
import com.xunmei.system.api.RemoteOrgService;
|
|
|
+import com.xunmei.system.api.RemoteUserService;
|
|
|
import com.xunmei.system.api.domain.SysOrg;
|
|
|
+import com.xunmei.system.api.domain.SysUser;
|
|
|
import com.xunmei.system.api.function.RemoteCallHandlerExecutor;
|
|
|
+import com.xunmei.system.api.vo.SysOrgVO;
|
|
|
+import io.netty.util.internal.StringUtil;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.util.Arrays;
|
|
|
-import java.util.List;
|
|
|
+import java.io.File;
|
|
|
+import java.util.*;
|
|
|
+import java.util.concurrent.CompletableFuture;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 人员出入登记Service业务层处理
|
|
|
@@ -38,9 +70,17 @@ import java.util.List;
|
|
|
public class CoreOutInRecordServiceImpl extends ServiceImpl<CoreOutInRecordMapper, CoreOutInRecord> implements ICoreOutInRecordService {
|
|
|
@Autowired
|
|
|
private CoreOutInRecordMapper coreOutInRecordMapper;
|
|
|
+ @Autowired
|
|
|
+ private CoreIntroduceLetterMapper letterMapper;
|
|
|
@Resource
|
|
|
private RemoteOrgService orgService;
|
|
|
-
|
|
|
+ @Resource
|
|
|
+ private RemoteFileService fileService;
|
|
|
+ @Autowired
|
|
|
+ private ICoreRegisterBookPdfService registerBookPdfService;
|
|
|
+ @Autowired
|
|
|
+ @Qualifier(ThreadPoolConfig.SOC_EXECUTOR)
|
|
|
+ private ThreadPoolTaskExecutor threadPoolTaskExecutor;
|
|
|
@Override
|
|
|
public TableDataInfo<CoreOutInRecordVo> selectPage(CoreOutInRecordRequestDto request) {
|
|
|
//未删除
|
|
|
@@ -51,13 +91,11 @@ public class CoreOutInRecordServiceImpl extends ServiceImpl<CoreOutInRecordMappe
|
|
|
} else {
|
|
|
page = new Page<>();
|
|
|
}
|
|
|
- if(ObjectUtil.isNotEmpty( request.getRange()))
|
|
|
- {
|
|
|
+ if (ObjectUtil.isNotEmpty(request.getRange())) {
|
|
|
request.setStartTime(DateUtil.beginOfDay(request.getRange()[0]));
|
|
|
request.setEndTime(DateUtil.endOfDay(request.getRange()[1]));
|
|
|
}
|
|
|
- if(ObjectUtil.isNotEmpty(request.getArrivalTime()))
|
|
|
- {
|
|
|
+ if (ObjectUtil.isNotEmpty(request.getArrivalTime())) {
|
|
|
request.setStartTime(DateUtil.beginOfDay(request.getArrivalTime()));
|
|
|
request.setEndTime(DateUtil.endOfDay(request.getArrivalTime()));
|
|
|
}
|
|
|
@@ -68,9 +106,8 @@ public class CoreOutInRecordServiceImpl extends ServiceImpl<CoreOutInRecordMappe
|
|
|
//获取数据
|
|
|
page = coreOutInRecordMapper.selectCoreOutInRecordPageList(page, request);
|
|
|
|
|
|
- if(ObjectUtil.isNotEmpty(page.getRecords()))
|
|
|
- {
|
|
|
- page.getRecords().forEach(vo->{
|
|
|
+ if (ObjectUtil.isNotEmpty(page.getRecords())) {
|
|
|
+ page.getRecords().forEach(vo -> {
|
|
|
vo.setLetterFile(ObjectUtil.isNotEmpty(vo.getLetterFileStr()) ? JSON.parseArray(vo.getLetterFileStr(), String.class) : null);
|
|
|
});
|
|
|
}
|
|
|
@@ -91,11 +128,11 @@ public class CoreOutInRecordServiceImpl extends ServiceImpl<CoreOutInRecordMappe
|
|
|
@Override
|
|
|
public CoreOutInRecordVo selectCoreOutInRecordById(Long id) {
|
|
|
|
|
|
- CoreOutInRecordVo vo = coreOutInRecordMapper.selectCoreOutInRecordById(id);
|
|
|
- if(ObjectUtil.isNotEmpty(vo)){
|
|
|
- vo.setLetterFile(ObjectUtil.isNotEmpty(vo.getLetterFileStr()) ? JSON.parseArray(vo.getLetterFileStr(), String.class) : null);
|
|
|
- }
|
|
|
- return vo;
|
|
|
+ CoreOutInRecordVo vo = coreOutInRecordMapper.selectCoreOutInRecordById(id);
|
|
|
+ if (ObjectUtil.isNotEmpty(vo)) {
|
|
|
+ vo.setLetterFile(ObjectUtil.isNotEmpty(vo.getLetterFileStr()) ? JSON.parseArray(vo.getLetterFileStr(), String.class) : null);
|
|
|
+ }
|
|
|
+ return vo;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -117,8 +154,7 @@ public class CoreOutInRecordServiceImpl extends ServiceImpl<CoreOutInRecordMappe
|
|
|
*/
|
|
|
@Override
|
|
|
public int insertCoreOutInRecord(CoreOutInRecord coreOutInRecord) {
|
|
|
- if(ObjectUtil.isEmpty(coreOutInRecord.getId()))
|
|
|
- {
|
|
|
+ if (ObjectUtil.isEmpty(coreOutInRecord.getId())) {
|
|
|
coreOutInRecord.setId(IdWorker.getId());
|
|
|
}
|
|
|
coreOutInRecord.setCreateTime(DateUtils.getNowDate());
|
|
|
@@ -158,4 +194,139 @@ public class CoreOutInRecordServiceImpl extends ServiceImpl<CoreOutInRecordMappe
|
|
|
public int deleteCoreOutInRecordById(Long id) {
|
|
|
return coreOutInRecordMapper.deleteById(id);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public AjaxResult buildOutInRecordPdf(Long id) {
|
|
|
+ final CoreOutInRecordVo record = selectCoreOutInRecordById(id);
|
|
|
+ final List<SysOrgVO> orgList = RedisUtils.getCacheList(CacheConstants.ORG_CACHE_LIST_KEY);
|
|
|
+ final SysOrgVO sysOrg = orgList.stream().filter(org -> ObjectUtil.equal(record.getOrgId(), org.getId())).findFirst().get();
|
|
|
+ String fileName = getFileOrgName(sysOrg) + "_" + RegisterBookType.VISIT_RECORD.getText() + "_" + DateUtil.format(new Date(), "yyyyMMddHHmmss") + ".pdf";
|
|
|
+ Map<String, Object> data = this.getFtlEdu(record, orgList);
|
|
|
+ data.put("fileName", fileName);
|
|
|
+ data.put("id", id);
|
|
|
+ // CompletableFuture.runAsync(() -> {
|
|
|
+ R<String> r = RemoteCallHandlerExecutor.executeRemoteCall(() -> fileService.generateOutInPdf(data), ErrorMsgConstants.GENERATE_PDF_ERROR);
|
|
|
+ if (null == r || null == r.getData()) {
|
|
|
+ throw new SystemException(ErrorMsgConstants.GENERATE_PDF_ERROR);
|
|
|
+ }
|
|
|
+ /* String pdfUrl = r.getData();
|
|
|
+ LambdaUpdateWrapper<CoreOutInRecord> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
+ updateWrapper.eq(CoreOutInRecord::getId, id);
|
|
|
+ updateWrapper.set(CoreEduTrainingTask::getPdfUrl, pdfUrl);
|
|
|
+ this.update(updateWrapper);*/
|
|
|
+
|
|
|
+ CoreRegisterBookPdf registerBookPdf = new CoreRegisterBookPdf();
|
|
|
+ registerBookPdf.setId(id);
|
|
|
+ registerBookPdf.setRegisterBookType(RegisterBookType.VISIT_RECORD.getNum());
|
|
|
+ registerBookPdf.setDate(new Date());
|
|
|
+ registerBookPdf.setOrgId(record.getLetterOrgId());
|
|
|
+ registerBookPdf.setOrgName(record.getOrgName());
|
|
|
+ registerBookPdf.setOrgPath(sysOrg.getPath());
|
|
|
+ /*registerBookPdf.setFileUrl(pdfUrl);
|
|
|
+ registerBookPdf.setFileName(StringUtils.substringAfterLast(pdfUrl, File.separator));
|
|
|
+ registerBookPdfService.save(registerBookPdf);*/
|
|
|
+ // }, threadPoolTaskExecutor);
|
|
|
+
|
|
|
+ return AjaxResult.success("正在生成pdf,请稍后刷新页面查看!");
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getFileOrgName(SysOrgVO org) {
|
|
|
+ String[] strings = org.getPath().split("-");
|
|
|
+ List<Long> list = Arrays.stream(strings).map(Long::valueOf).collect(Collectors.toList());
|
|
|
+ List<SysOrg> sysOrgList = RemoteCallHandlerExecutor.executeRemoteCall(() -> orgService.selectOrgByIdList(list, SecurityConstants.INNER), ErrorMsgConstants.QUERY_ORG_DATA_ERROR);
|
|
|
+ final Map<Long, String> map = sysOrgList.stream().collect(Collectors.toMap(SysOrg::getId, SysOrg::getShortName));
|
|
|
+ List<String> list1 = new ArrayList<>();
|
|
|
+ for (String orgId : strings) {
|
|
|
+ list1.add(map.get(Long.parseLong(orgId)));
|
|
|
+ }
|
|
|
+ return String.join("_", list1);
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<String, Object> getFtlEdu(CoreOutInRecordVo record, List<SysOrgVO> orgList) {
|
|
|
+ final CoreIntroduceLetterApproveLog approveLog = letterMapper.findCheckLog(record.getLetterId(), record.getOrgId());
|
|
|
+ final SysOrgVO inOrg = orgList.stream().filter(org -> ObjectUtil.equal(org.getId(), record.getOrgId())).findFirst().get();
|
|
|
+ final SysOrgVO outOrg = orgList.stream().filter(org -> ObjectUtil.equal(org.getId(), record.getLetterOrgId())).findFirst().get();
|
|
|
+ String prefixPath = RemoteCallHandlerExecutor.executeRemoteCall(() -> fileService.getLocalPathPrefix(), ErrorMsgConstants.QUERY_FILE_PATH_ERROR);
|
|
|
+ String staticsPath = RemoteCallHandlerExecutor.executeRemoteCall(() -> fileService.getStaticPathPrefix(), ErrorMsgConstants.QUERY_FILE_PATH_ERROR);
|
|
|
+
|
|
|
+ Map<String, Object> data = new HashMap<>();
|
|
|
+
|
|
|
+ //接待机构
|
|
|
+ String inOrgName = ObjectUtil.isNotEmpty(inOrg.getShortName()) ? inOrg.getShortName() : inOrg.getName();
|
|
|
+ data.put("inOrg", inOrgName);
|
|
|
+ //接待日期
|
|
|
+ String time = DateUtil.format(record.getArrivalTime(), "yyyy年MM月dd日");
|
|
|
+ data.put("time", StringUtils.isNotEmpty(time) ? time : StringUtil.EMPTY_STRING);
|
|
|
+ //来访事由
|
|
|
+ data.put("reasons", StringUtils.isNotEmpty(record.getReasons()) ? record.getReasons() : StringUtil.EMPTY_STRING);
|
|
|
+ //审批人
|
|
|
+ data.put("approveUser", StringUtils.isNotEmpty(approveLog.getApproveUser()) ? approveLog.getApproveUser() : StringUtil.EMPTY_STRING);
|
|
|
+ //来访单位
|
|
|
+ String outOrgName = ObjectUtil.isNotEmpty(outOrg.getShortName()) ? outOrg.getShortName() : outOrg.getName();
|
|
|
+ data.put("outOrgName", outOrgName);
|
|
|
+ //来访人员
|
|
|
+ data.put("userName", record.getUserName());
|
|
|
+ //证件类型
|
|
|
+ /* final CoreIntroduceLetterUser letterUser = letterUserMapper.selectOne(new LambdaQueryWrapper<CoreIntroduceLetterUser>()
|
|
|
+ .eq(CoreIntroduceLetterUser::getLetterId, record.getLetterId())
|
|
|
+ .eq(CoreIntroduceLetterUser::getId, record.getLetterUserId()));
|
|
|
+ final String idTypeLabel = DictUtils.getDictLabel(DictConstants.LETTER_ID_TYPE, letterUser.getIdType());*/
|
|
|
+ data.put("idType", record.getIdType());
|
|
|
+ //证件号码
|
|
|
+ data.put("idCard", record.getIdCard());
|
|
|
+
|
|
|
+ //进入时间
|
|
|
+ String inTime = DateUtil.format(record.getArrivalTime(), "yyyy年MM月dd日HH时mm分");
|
|
|
+ data.put("inTime", inTime);
|
|
|
+ //离开时间
|
|
|
+ String outTime = DateUtil.format(record.getDepartureTime(), "yyyy年MM月dd日HH时mm分");
|
|
|
+ data.put("outTime", outTime);
|
|
|
+ //证件图片
|
|
|
+ final String imgFile = record.getImgFile();
|
|
|
+ if (ObjectUtil.isEmpty(imgFile)) {
|
|
|
+ data.put("imageFile", new ArrayList<>());
|
|
|
+ } else {
|
|
|
+ data.put("imageFile", getFileRealPath(Arrays.asList(imgFile.split(",")), prefixPath, staticsPath));
|
|
|
+ }
|
|
|
+ //介绍信附件
|
|
|
+ final String file = record.getLetterFileStr();
|
|
|
+ if (ObjectUtil.isEmpty(file)) {
|
|
|
+ data.put("file", new ArrayList<>());
|
|
|
+ } else {
|
|
|
+ final List<String> list = JSON.parseArray(file, String.class);
|
|
|
+ List<String> strings = new ArrayList<>();
|
|
|
+ for (String json : list) {
|
|
|
+ final Map map = JSON.parseObject(json, Map.class);
|
|
|
+ final String url = (String)map.get("url");
|
|
|
+ if (ObjectUtil.isNotEmpty(url)){
|
|
|
+ strings.add(url);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ data.put("file", getFileRealPath(strings, prefixPath, staticsPath));
|
|
|
+ }
|
|
|
+ //核验图片
|
|
|
+ final String checkImage = record.getCheckImage();
|
|
|
+ if (ObjectUtil.isEmpty(checkImage) || !checkImage.contains(File.separator)) {
|
|
|
+ data.put("checkImage", new ArrayList<>());
|
|
|
+ } else {
|
|
|
+ data.put("checkImage", getFileRealPath(Arrays.asList(checkImage.split(",")), prefixPath, staticsPath));
|
|
|
+ }
|
|
|
+ return data;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private List<String> getFileRealPath(List<String> fileList, String prefixPath, String staticsPath) {
|
|
|
+ List<String> list = new ArrayList<>();
|
|
|
+ if (ObjectUtil.isEmpty(fileList)) {
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+ for (String path : fileList) {
|
|
|
+ if (path.contains(staticsPath)) {
|
|
|
+ //删除 /statics 前缀路径
|
|
|
+ path = path.replace(staticsPath, StringUtil.EMPTY_STRING);
|
|
|
+ }
|
|
|
+ list.add(prefixPath + path);
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
}
|