|
|
@@ -14,8 +14,13 @@ import com.gz.common.DataGlobalVariable;
|
|
|
import com.gz.core.exception.BusinessException;
|
|
|
import com.gz.core.exception.CustomExceptionEnum;
|
|
|
import com.gz.dto.archive.ArchiveDTO;
|
|
|
+import com.gz.dto.archive.SecondaryArchiveDTO;
|
|
|
+import com.gz.dto.archive.SecondaryArchiveDTO;
|
|
|
import com.gz.dto.system.ArchivesTreeDTO;
|
|
|
+import com.gz.dto.system.MenuRoleDTO;
|
|
|
import com.gz.mapper.archive.ArchiveMapper;
|
|
|
+import com.gz.mapper.archive.SecondaryArchiveMapper;
|
|
|
+import com.gz.mapper.system.MenuRoleMapper;
|
|
|
import com.gz.rvo.archive.ArchiveRVO;
|
|
|
import com.gz.rvo.borrow.ArchiveBorrowListRVO;
|
|
|
import com.gz.service.archive.ArchiveService;
|
|
|
@@ -60,6 +65,9 @@ public class ArchiveServiceImpl implements ArchiveService {
|
|
|
private ArchiveMapper mapper;
|
|
|
|
|
|
@Resource
|
|
|
+ private SecondaryArchiveMapper secondaryArchiveMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
private ArchivesTreeService archivesTreeService;
|
|
|
|
|
|
@Autowired
|
|
|
@@ -71,6 +79,9 @@ public class ArchiveServiceImpl implements ArchiveService {
|
|
|
@Resource
|
|
|
private StringRedisTemplate stringRedisTemplate;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private MenuRoleMapper menuRoleMapper;
|
|
|
+
|
|
|
|
|
|
@Override
|
|
|
public Integer insert(InsertArchiveVO vo) throws Exception {
|
|
|
@@ -225,7 +236,7 @@ public class ArchiveServiceImpl implements ArchiveService {
|
|
|
public String generateDh(GenerateDhVO vo) {
|
|
|
String jh = String.format("%05d", vo.getJh());
|
|
|
ArchivesTreeDTO dto = archivesTreeService.selectParentByCode(vo.getSl());
|
|
|
- if (dto != null){
|
|
|
+ if (dto != null) {
|
|
|
vo.setMl(dto.getCode());
|
|
|
}
|
|
|
|
|
|
@@ -253,20 +264,20 @@ public class ArchiveServiceImpl implements ArchiveService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public List<ArchiveDTO> importExcel(MultipartFile file) throws IOException {
|
|
|
- InputStream inputStream = file.getInputStream();
|
|
|
+ /**
|
|
|
+ * @description 导入档案目录
|
|
|
+ * @author LiuChangLan
|
|
|
+ * @since 2021/4/9 9:28
|
|
|
+ */
|
|
|
+ private List<ArchiveDTO> importArchive(InputStream inputStream) {
|
|
|
ExcelReader reader = ExcelUtil.getReader(inputStream, 0);
|
|
|
List<List<Object>> rows = reader.read();
|
|
|
List<ArchiveDTO> result = new ArrayList<>();
|
|
|
for (int i = 1; i < rows.size(); i++) {
|
|
|
- if (i == 1123){
|
|
|
- System.out.println(1);
|
|
|
- }
|
|
|
try {
|
|
|
List<Object> row = rows.get(i);
|
|
|
ArchiveDTO dto = new ArchiveDTO();
|
|
|
- dto.setMl("WS");
|
|
|
+ dto.setMl(ExcelUtils.getExcelCellStringValue(row, 29));
|
|
|
dto.setDagdm(ExcelUtils.getExcelCellStringValue(row, 0));
|
|
|
dto.setDh(ExcelUtils.getExcelCellStringValue(row, 1));
|
|
|
dto.setQzh(ExcelUtils.getExcelCellStringValue(row, 2));
|
|
|
@@ -274,22 +285,38 @@ public class ArchiveServiceImpl implements ArchiveService {
|
|
|
dto.setMj(ExcelUtils.getExcelCellStringValue(row, 4));
|
|
|
dto.setBgqx(ExcelUtils.getExcelCellStringValue(row, 5));
|
|
|
// TODO: 2021/2/25 机构代号 6 馆编号 7
|
|
|
- dto.setJh(ExcelUtils.getExcelCellIntegerValue(row,7));
|
|
|
+ dto.setJh(ExcelUtils.getExcelCellIntegerValue(row, 7));
|
|
|
dto.setZtsl(ExcelUtils.getExcelCellIntegerValue(row, 8));
|
|
|
dto.setWjbh(ExcelUtils.getExcelCellStringValue(row, 9));
|
|
|
- DateTime wjxcsj = DateUtil.parse(ExcelUtils.getExcelCellStringValue(row, 10), "yyyyMMdd");
|
|
|
+ DateTime wjxcsj = null;
|
|
|
+ if ("WS".equals(dto.getMl())) {
|
|
|
+ wjxcsj = DateUtil.parse(ExcelUtils.getExcelCellStringValue(row, 10), "yyyyMMdd");
|
|
|
+ } else {
|
|
|
+ wjxcsj = DateUtil.parse(ExcelUtils.getExcelCellStringValue(row, 10), "yyyyMM");
|
|
|
+ }
|
|
|
dto.setWjxcsj(DateUtil.formatDate(wjxcsj));
|
|
|
- String wjdqsj = "";
|
|
|
- switch (dto.getBgqx()) {
|
|
|
- case "005":
|
|
|
- case "D10":
|
|
|
- wjdqsj = DateUtil.formatDate(DateUtil.offset(wjxcsj, DateField.YEAR, 10));
|
|
|
- break;
|
|
|
- case "004":
|
|
|
- case "D30":
|
|
|
- wjdqsj = DateUtil.formatDate(DateUtil.offset(wjxcsj, DateField.YEAR, 30));
|
|
|
- break;
|
|
|
+ String wjdqsj = ExcelUtils.getExcelCellStringValue(row, 30);
|
|
|
+ if (StrUtil.isEmpty(wjdqsj)) {
|
|
|
+ switch (dto.getBgqx()) {
|
|
|
+ case "005":
|
|
|
+ case "D10":
|
|
|
+ wjdqsj = DateUtil.formatDate(DateUtil.offset(wjxcsj, DateField.YEAR, 10));
|
|
|
+ break;
|
|
|
+ case "004":
|
|
|
+ case "D30":
|
|
|
+ wjdqsj = DateUtil.formatDate(DateUtil.offset(wjxcsj, DateField.YEAR, 30));
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ DateTime wjdqsjDate = null;
|
|
|
+ if ("WS".equals(dto.getMl())) {
|
|
|
+ wjdqsjDate = DateUtil.parse(wjdqsj, "yyyyMMdd");
|
|
|
+ } else {
|
|
|
+ wjdqsjDate = DateUtil.parse(wjdqsj, "yyyyMM");
|
|
|
+ }
|
|
|
+ dto.setWjdqsj(DateUtil.formatDate(wjdqsjDate));
|
|
|
}
|
|
|
+
|
|
|
dto.setWjdqsj(wjdqsj);
|
|
|
dto.setZrz(ExcelUtils.getExcelCellStringValue(row, 11));
|
|
|
dto.setTm(ExcelUtils.getExcelCellStringValue(row, 12));
|
|
|
@@ -308,36 +335,114 @@ public class ArchiveServiceImpl implements ArchiveService {
|
|
|
dto.setFlh(ExcelUtils.getExcelCellStringValue(row, 25));
|
|
|
dto.setZtc(ExcelUtils.getExcelCellStringValue(row, 26));
|
|
|
dto.setQwbs(ExcelUtils.getExcelCellStringValue(row, 27));
|
|
|
- dto.setMj("NABU");
|
|
|
+ dto.setMlh(ExcelUtils.getExcelCellStringValue(row, 28));
|
|
|
+// dto.setMj("NABU");
|
|
|
result.add(dto);
|
|
|
} catch (Exception e) {
|
|
|
- throw new BusinessException(500, String.format("导入出错,错误位置:%s行,错误原因:%s", (i + 1), e.getMessage()));
|
|
|
+ throw new BusinessException(500, String.format("【档案目录】解析出错,错误位置:%s行,错误原因:%s", (i + 1), e.getMessage()));
|
|
|
}
|
|
|
}
|
|
|
- stringRedisTemplate.opsForValue().set(request.getSession().getId(), JSONObject.toJSONString(result), 1L, TimeUnit.HOURS);
|
|
|
- log.info("成功解析:[{}],共有{}条数据", file.getOriginalFilename(), result.size());
|
|
|
+ String redisKey = String.format(DataGlobalVariable.IMPORT_ARCHIVE_SESSION_KEY_FOMAT, request.getSession().getId());
|
|
|
+ stringRedisTemplate.opsForValue().set(redisKey, JSONObject.toJSONString(result), 1L, TimeUnit.HOURS);
|
|
|
+ log.info("【档案目录】成功解析,共有{}条档案目录数据", result.size());
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description 导入二级目录
|
|
|
+ * @author LiuChangLan
|
|
|
+ * @since 2021/4/9 9:31
|
|
|
+ */
|
|
|
+ private List<SecondaryArchiveDTO> importSecondaryArchive(InputStream inputStream) {
|
|
|
+ ExcelReader reader = ExcelUtil.getReader(inputStream, 1);
|
|
|
+ List<List<Object>> rows = reader.read();
|
|
|
+ List<SecondaryArchiveDTO> result = new ArrayList<>();
|
|
|
+ for (int i = 1; i < rows.size(); i++) {
|
|
|
+ try {
|
|
|
+ List<Object> row = rows.get(i);
|
|
|
+ SecondaryArchiveDTO dto = new SecondaryArchiveDTO();
|
|
|
+ // 档号Str
|
|
|
+ dto.setDh(ExcelUtils.getExcelCellStringValue(row, 0));
|
|
|
+ // 顺序号
|
|
|
+ dto.setSxh(ExcelUtils.getExcelCellIntegerValue(row, 1));
|
|
|
+ // 文号
|
|
|
+ dto.setWh(ExcelUtils.getExcelCellStringValue(row, 2));
|
|
|
+ // 责任者
|
|
|
+ dto.setZrz(ExcelUtils.getExcelCellStringValue(row, 3));
|
|
|
+ // 题名
|
|
|
+ dto.setTm(ExcelUtils.getExcelCellStringValue(row, 4));
|
|
|
+ // 日期
|
|
|
+ if (StrUtil.isEmpty(ExcelUtils.getExcelCellStringValue(row, 5))) {
|
|
|
+ dto.setRq("");
|
|
|
+ } else {
|
|
|
+ DateTime rq = DateUtil.parse(ExcelUtils.getExcelCellStringValue(row, 5), "yyyyMMdd");
|
|
|
+ dto.setRq(DateUtil.formatDate(rq));
|
|
|
+ }
|
|
|
+ // 页号
|
|
|
+ dto.setYh(ExcelUtils.getExcelCellStringValue(row, 6));
|
|
|
+ // 备注
|
|
|
+ dto.setBz(ExcelUtils.getExcelCellStringValue(row, 7));
|
|
|
+ result.add(dto);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new BusinessException(500, String.format("【卷内目录】解析出错,错误位置:%s行,错误原因:%s", (i + 1), e.getMessage()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String redisKey = String.format(DataGlobalVariable.IMPORT_SECONDARY_ARCHIVE_SESSION_KEY_FOMAT, request.getSession().getId());
|
|
|
+ stringRedisTemplate.opsForValue().set(redisKey, JSONObject.toJSONString(result), 1L, TimeUnit.HOURS);
|
|
|
+ log.info("【卷内目录】成功解析,共有{}条档案目录数据", result.size());
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ public List<ArchiveDTO> importExcel(MultipartFile file) throws IOException {
|
|
|
+ List<ArchiveDTO> archiveDTOS = importArchive(file.getInputStream());
|
|
|
+ importSecondaryArchive(file.getInputStream());
|
|
|
+ return archiveDTOS;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
public ArchiveRVO selectByPrimaryKeyText(Integer id) {
|
|
|
+ MenuRoleDTO param = new MenuRoleDTO();
|
|
|
+ param.setRoleId(JwtUtils.getCurrentUserJwtPayload().getRoleId());
|
|
|
+ param.setRoleType(DataGlobalVariable.ARCHIVE_SHOW);
|
|
|
+ if (menuRoleMapper.select(param).stream().filter(i -> i.getMenuId() == 1).count() <= 0) {
|
|
|
+ throw new BusinessException(CustomExceptionEnum.NO_ROLE);
|
|
|
+ }
|
|
|
+
|
|
|
return mapper.selectByPrimaryKeyText(id);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@Transactional
|
|
|
public Integer confirmImport() {
|
|
|
- Integer count = 0;
|
|
|
- String s = stringRedisTemplate.opsForValue().get(request.getSession().getId());
|
|
|
- if (StrUtil.isEmpty(s)){
|
|
|
- throw new BusinessException(500,"请先上传文件");
|
|
|
+ Integer archiveCount = 0;
|
|
|
+ Integer secondaryArchiveCount = 0;
|
|
|
+ String archiveRedisKey = String.format(DataGlobalVariable.IMPORT_ARCHIVE_SESSION_KEY_FOMAT, request.getSession().getId());
|
|
|
+ String secondaryArchiveRedisKey = String.format(DataGlobalVariable.IMPORT_SECONDARY_ARCHIVE_SESSION_KEY_FOMAT, request.getSession().getId());
|
|
|
+ // 读取缓存中的档案数据
|
|
|
+ String archiveJsonStr = stringRedisTemplate.opsForValue().get(archiveRedisKey);
|
|
|
+ // 读取缓存中的卷内目录数据
|
|
|
+ String secondaryArchiveJsonStr = stringRedisTemplate.opsForValue().get(secondaryArchiveRedisKey);
|
|
|
+ if (StrUtil.isEmpty(archiveJsonStr)) {
|
|
|
+ throw new BusinessException(500, "请先上传文件");
|
|
|
}
|
|
|
- List<ArchiveDTO> archiveDTOS = JSONObject.parseArray(s, ArchiveDTO.class);
|
|
|
+ List<ArchiveDTO> archiveDTOS = JSONObject.parseArray(archiveJsonStr, ArchiveDTO.class);
|
|
|
+ List<SecondaryArchiveDTO> secondaryArchiveDTOs = JSONObject.parseArray(secondaryArchiveJsonStr, SecondaryArchiveDTO.class);
|
|
|
for (ArchiveDTO archiveDTO : archiveDTOS) {
|
|
|
- count += mapper.insertSelective(archiveDTO);
|
|
|
+ archiveCount += mapper.insertSelective(archiveDTO);
|
|
|
+ stringRedisTemplate.opsForValue().set(archiveDTO.getDh(), String.valueOf(archiveDTO.getId()), 1L, TimeUnit.DAYS);
|
|
|
+ }
|
|
|
+ for (SecondaryArchiveDTO dto : secondaryArchiveDTOs) {
|
|
|
+ String dh = dto.getDh();
|
|
|
+ String archiveDh = dh.substring(0, dh.lastIndexOf("-"));
|
|
|
+ int archiveId = Integer.parseInt(stringRedisTemplate.opsForValue().get(archiveDh));
|
|
|
+ dto.setArchiveId(archiveId);
|
|
|
+ secondaryArchiveCount += secondaryArchiveMapper.insertSelective(dto);
|
|
|
}
|
|
|
- log.info("确定导入{}条数据",count);
|
|
|
- stringRedisTemplate.delete(request.getSession().getId());
|
|
|
- return count;
|
|
|
+ log.info("【档案目录】确定导入{}条数据", archiveCount);
|
|
|
+ log.info("【卷内目录】确定导入{}条数据", secondaryArchiveCount);
|
|
|
+ stringRedisTemplate.delete(archiveRedisKey);
|
|
|
+ stringRedisTemplate.delete(secondaryArchiveRedisKey);
|
|
|
+ return archiveCount;
|
|
|
}
|
|
|
}
|