123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709 |
- package cn.cslg.pas.service.business;
- import cn.cslg.pas.common.core.base.Cycle;
- import cn.cslg.pas.common.dto.ExportTaskDTO;
- import cn.cslg.pas.common.dto.ImportTaskDTO;
- import cn.cslg.pas.common.dto.PatentStarListDTO;
- import cn.cslg.pas.common.importTask.QuartzConditionDTO;
- import cn.cslg.pas.common.model.cronModel.Personnel;
- import cn.cslg.pas.common.model.cronModel.PersonnelVO;
- import cn.cslg.pas.common.model.cronModel.Records;
- import cn.cslg.pas.common.model.cronModel.SystemFile;
- import cn.cslg.pas.common.model.importPDF.AddImportPDFTaskDTO;
- import cn.cslg.pas.common.model.request.GroupRequest;
- import cn.cslg.pas.common.model.request.QueryRequest;
- import cn.cslg.pas.common.utils.*;
- import cn.cslg.pas.common.vo.ImportTaskAMVO;
- import cn.cslg.pas.common.vo.StarPatentVO;
- import cn.cslg.pas.common.vo.business.ImportTaskVO;
- import cn.cslg.pas.domain.business.*;
- import cn.cslg.pas.exception.UnLoginException;
- import cn.cslg.pas.exception.XiaoShiException;
- import cn.cslg.pas.factorys.businessFactory.Business;
- import cn.cslg.pas.mapper.ImportTaskMapper;
- import cn.cslg.pas.service.MailSendService;
- import cn.cslg.pas.service.common.FileManagerService;
- import cn.cslg.pas.service.common.PatentStarApiService;
- import cn.cslg.pas.service.importPatent.SchedulingTaskService;
- import cn.cslg.pas.service.permissions.PermissionService;
- import cn.cslg.pas.service.query.FormatQueryService;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import lombok.RequiredArgsConstructor;
- import org.apache.commons.compress.utils.IOUtils;
- import org.apache.poi.ss.usermodel.Sheet;
- import org.joda.time.DateTime;
- import org.springframework.beans.BeanUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.context.annotation.Lazy;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import org.springframework.web.multipart.MultipartFile;
- import java.io.*;
- import java.time.LocalDate;
- import java.util.*;
- import java.util.stream.Collectors;
- /**
- * 导入任务表业务层
- *
- * @author chenyu
- * @date 2023/10/20
- */
- @Service
- @RequiredArgsConstructor
- public class ImportTaskService extends ServiceImpl<ImportTaskMapper, ImportTask> implements Business {
- @Autowired
- private FormatQueryService formatQueryService;
- @Autowired
- private ImportTaskMapper importTaskMapper;
- @Autowired
- private FileManagerService fileManagerService;
- @Autowired
- private PatentStarApiService patentStarApiService;
- @Autowired
- private PermissionService permissionService;
- @Autowired
- @Lazy
- private SchedulingTaskService schedulingTaskService;
- @Autowired
- private CacheUtils cacheUtils;
- @Autowired
- private LoginUtils loginUtils;
- @Autowired
- private SystemDictService systemDictService;
- @Autowired
- private ProductService productService;
- @Autowired
- private ProjectService projectService;
- @Autowired
- private ImportTaskConditionService importTaskConditionService;
- @Autowired
- private MailSendService mailSendService;
- @Autowired
- private PatentProjectService patentProjectService;
- @Override
- public Object queryMessage(QueryRequest queryRequest) throws Exception {
- List<String> sqls = formatQueryService.reSqls(queryRequest, "importTask");
- this.loadSearchSql(sqls, queryRequest.getProjectId());
- //根据sql查询事件信息
- List<ImportTaskVO> importTaskVOS = importTaskMapper.getImportTask(sqls.get(0), sqls.get(1), sqls.get(2));
- //查询总数
- Long total = importTaskMapper.getImportTaskCount(sqls.get(0));
- //装载事件信息
- this.loadImportTask(importTaskVOS);
- Records records = new Records();
- records.setCurrent(queryRequest.getCurrent());
- records.setSize(queryRequest.getSize());
- records.setData(importTaskVOS);
- records.setTotal(total);
- return records;
- }
- @Override
- public Object addMessage(Object object, List<MultipartFile> files) {
- return null;
- }
- @Override
- public Object deleteMessage(List<Integer> ids) throws IOException {
- return null;
- }
- @Override
- public Object updateMessage(Object object, List<MultipartFile> files) {
- return null;
- }
- @Override
- public Object getGroup(GroupRequest groupRequest, String tableName) throws Exception {
- return null;
- }
- @Override
- @Transactional(rollbackFor = Exception.class)
- public Object addMessage(Object object) {
- if (object == null) {
- throw new XiaoShiException("参数不能为空");
- }
- //TODO 校验参数
- ImportTaskDTO importTaskDTO = (ImportTaskDTO) object;
- Boolean ifUpdate = importTaskDTO.getIfUpdate();
- PersonnelVO personnelVO = new PersonnelVO();
- personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
- if (importTaskDTO.getType() == null) {
- importTaskDTO.setType(4);
- }
- List<String> addPatentNos = importTaskDTO.getPatentNos();
- if (!importTaskDTO.getType().equals(1)) {
- importTaskDTO.setImportContent(MathUtils.BinaryToDecimal(importTaskDTO.getImportContent()));
- }
- ImportTaskCondition importTaskCondition = new ImportTaskCondition();
- if (ifUpdate != null && ifUpdate) {
- QuartzConditionDTO quartzConditionDTO = new QuartzConditionDTO();
- BeanUtils.copyProperties(importTaskDTO, quartzConditionDTO);
- importTaskCondition = importTaskConditionService.addQuartzCondition(quartzConditionDTO);
- } else {
- importTaskCondition = importTaskConditionService.addQuartzCondition(importTaskDTO);
- }
- //装载任务
- ImportTask importTask = new ImportTask();
- importTask.setImportTaskConditionId(importTaskCondition.getId());
- importTask.setType(importTaskDTO.getType());
- importTask.setSearchCondition(importTaskDTO.getSearchCondition());
- importTask.setCreateId(personnelVO.getId());
- if (importTaskCondition.getType().equals(1)) {
- try {
- String res = fileManagerService.getSystemFileFromFMS(Arrays.asList(importTaskCondition.getFileGuid()));
- List<SystemFile> systemFiles = JSONArray.parseArray(res, SystemFile.class);
- SystemFile systemFile = systemFiles.get(0);
- String suffix = systemFile.getFileName().substring(systemFile.getFileName().lastIndexOf("."));
- //调用文件系统取出文件接口,获得文件流
- byte[] bytes = fileManagerService.downloadSystemFileFromFMS(importTaskCondition.getFileGuid());
- //创建临时文件tempFile,并将文件读取到tempFile
- File tempFile = File.createTempFile(systemFile.getFileName() + "temp", suffix);
- try (
- InputStream inputStream = new ByteArrayInputStream(bytes);
- FileOutputStream outputStream = new FileOutputStream(tempFile);
- ) {
- IOUtils.copy(inputStream, outputStream); // 将输入流复制到临时文件
- }
- Integer totalNum = ReadExcelUtils.textExcel(tempFile, importTaskCondition.getSourceId().toString());
- importTask.setAllNum(totalNum);
- //删除临时文件tempFile
- new File(tempFile.getPath()).delete();
- } catch (Exception e) {
- e.printStackTrace();
- throw new XiaoShiException(e.getMessage());
- }
- } else if (importTaskCondition.getType().equals(4)) {
- try {
- if (addPatentNos == null || addPatentNos.size() == 0) {
- PatentStarListDTO patentStarListDto = new PatentStarListDTO()
- .setCurrentQuery(importTaskCondition.getSearchCondition())
- .setOrderBy(importTaskCondition.getOrderBy())
- .setOrderByType(importTaskCondition.getOrderByType())
- .setPageNum(1)
- .setRowCount(10)
- .setDBType(importTaskCondition.getDbType());
- //调用一般接口返回一批专利著录相关数据
- Map<String, Object> resultMap = patentStarApiService.patentStarSearchApi(patentStarListDto);
- if (resultMap == null || (Integer) resultMap.get("total") == 0) {
- ThrowException.throwXiaoShiException("未检索到相关专利");
- } else {
- importTask.setAllNum((Integer) resultMap.get("total"));
- }
- } else {
- importTask.setAllNum(addPatentNos.size());
- }
- } catch (Exception e) {
- throw new XiaoShiException("文件错误");
- }
- } else if (importTaskCondition.getType().equals(2) || importTaskCondition.getType().equals(3)) {
- List<String> patentNos = new ArrayList<>();
- if (importTaskCondition.getType().equals(2)) {
- patentNos = Arrays.asList(importTaskCondition.getSearchCondition().split("[,|,]"));
- } else if (importTaskCondition.getType().equals(3)) {
- try {
- String res = fileManagerService.getSystemFileFromFMS(Arrays.asList(importTaskCondition.getFileGuid()));
- List<SystemFile> systemFiles = JSONArray.parseArray(res, SystemFile.class);
- SystemFile systemFile = systemFiles.get(0);
- String suffix = systemFile.getFileName().substring(systemFile.getFileName().lastIndexOf("."));
- //调用文件系统取出文件接口,获得文件流
- byte[] bytes = fileManagerService.downloadSystemFileFromFMS(importTaskCondition.getFileGuid());
- //创建临时文件tempFile,并将文件读取到tempFile
- File tempFile = File.createTempFile(systemFile.getFileName() + "temp", suffix);
- try (
- InputStream inputStream = new ByteArrayInputStream(bytes);
- FileOutputStream outputStream = new FileOutputStream(tempFile)
- ) {
- IOUtils.copy(inputStream, outputStream); // 将输入流复制到临时文件
- }
- Sheet sheet = ReadExcelUtils.readExcel(tempFile);
- patentNos = ReadExcelUtils.getPatentNoFromExcel(sheet);
- } catch (Exception e) {
- }
- }
- importTask.setAllNum(patentNos.size());
- }
- importTask.setProgress(0.0);
- String taskName = this.setImportTaskName(importTaskCondition, personnelVO.getName());
- importTask.setName(taskName);
- importTask.insert();
- schedulingTaskService.startTask();
- return importTask.getId();
- }
- @Override
- public Object updateMessage(Object object) {
- return null;
- }
- private void loadImportTask(List<ImportTaskVO> importTaskVOS) throws IOException {
- List<ImportTaskAMVO> importTaskAMVOS = schedulingTaskService.getImportTaskAMVOs();
- if (importTaskAMVOS == null) {
- importTaskAMVOS = new ArrayList<>();
- }
- List<String> createIds = new ArrayList<>();
- List<Integer> projectIds = new ArrayList<>();
- List<Integer> productIds = new ArrayList<>();
- List<String> guids = new ArrayList<>();
- importTaskVOS.forEach(item -> {
- if (item.getCreateId() != null) {
- createIds.add(item.getCreateId());
- }
- if (item.getProductId() != null) {
- productIds.add(item.getProductId());
- }
- if (item.getProjectId() != null) {
- projectIds.add(item.getProjectId());
- }
- if (item.getFileGuid() != null) {
- guids.add(item.getFileGuid());
- }
- });
- List<Personnel> personnels = new ArrayList<>();
- List<Product> products = new ArrayList<>();
- List<Project> projects = new ArrayList<>();
- List<SystemFile> systemFiles = new ArrayList<>();
- //查询创建人名称
- if (createIds.size() != 0) {
- String res = permissionService.getPersonnelByIdsFromPCS(createIds);
- JSONObject jsonObject = JSONObject.parseObject(res);
- personnels = JSONObject.parseArray(jsonObject.getString("data"), Personnel.class);
- }
- //查询项目名称
- if (projectIds.size() != 0) {
- LambdaQueryWrapper<Project> queryWrapper = new LambdaQueryWrapper<>();
- queryWrapper.in(Project::getId, projectIds);
- projects = projectService.list(queryWrapper);
- }
- //查询产品名称
- if (productIds.size() != 0) {
- LambdaQueryWrapper<Product> queryWrapper = new LambdaQueryWrapper<>();
- queryWrapper.in(Product::getId, productIds);
- products = productService.list(queryWrapper);
- }
- //查询文件
- if (guids.size() != 0) {
- String res = fileManagerService.getSystemFileFromFMS(guids);
- systemFiles = JSONObject.parseArray(res, SystemFile.class);
- if (systemFiles == null) {
- systemFiles = new ArrayList<>();
- }
- }
- LambdaQueryWrapper<SystemDict> lambdaQueryWrapper = new LambdaQueryWrapper<>();
- lambdaQueryWrapper.eq(SystemDict::getGroupType, "IMPORT_TASK");
- List<SystemDict> systemDictList = systemDictService.list(lambdaQueryWrapper);
- for (ImportTaskVO importTaskVO : importTaskVOS) {
- //装载创建人
- Personnel personnel = personnels.stream().filter(item -> item.getId().equals(importTaskVO.getCreateId())).findFirst().orElse(null);
- if (personnel != null) {
- importTaskVO.setCreateName(personnel.getPersonnelName());
- }
- //装载状态
- SystemDict systemDict1 = systemDictList.stream()
- .filter(item -> item.getType().equals("IMPORT_TASK_TYPE") && item.getType()
- .equals(importTaskVO.getType().toString())).findFirst().orElse(null);
- SystemDict systemDict2 = systemDictList.stream()
- .filter(item -> item.getType().equals("IMPORT_TASk_STATE") && item.getType()
- .equals(importTaskVO.getState().toString())).findFirst().orElse(null);
- if (systemDict1 != null) {
- importTaskVO.setTypeStr(systemDict1.getLabel());
- }
- if (systemDict2 != null) {
- importTaskVO.setStateStr(systemDict2.getLabel());
- }
- //装载正在进行中任务的完成条数
- ImportTaskAMVO importTaskAMVO = importTaskAMVOS.stream().filter(item -> item.getId().equals(importTaskVO.getId())).findFirst().orElse(null);
- if (importTaskAMVO != null) {
- importTaskVO.setDoneNum(importTaskAMVO.getDoneNum());
- importTaskAMVO.setAllNum(importTaskAMVO.getAllNum());
- }
- long percentage = (long) Math.floor((importTaskVO.getDoneNum() + 0D) / importTaskVO.getAllNum() * 100D);
- importTaskVO.setPercentage(percentage);
- //装载目标名称
- if (projects.size() > 0 && importTaskVO.getProjectId() != null) {
- Project project = projects.stream().filter(item -> item.getId().equals(importTaskVO.getProjectId())).findFirst().orElse(null);
- if (project != null) {
- importTaskVO.setImportToId(project.getId());
- importTaskVO.setImportToType(project.getType() - 1);
- if (project.getType().equals(1)) {
- importTaskVO.setImportToName(project.getName() + "-专利数据库");
- } else {
- importTaskVO.setImportToName(project.getName() + "-报告");
- }
- }
- } else if (products.size() > 0 && importTaskVO.getProductId() != null) {
- Product product = products.stream().filter(item -> item.getId().equals(importTaskVO.getProductId())).findFirst().orElse(null);
- if (product != null) {
- importTaskVO.setImportToId(product.getId());
- importTaskVO.setImportToType(2);
- importTaskVO.setImportToName(product.getName());
- }
- }
- if (importTaskVO.getFileGuid() != null) {
- SystemFile systemFile = systemFiles.stream().filter(item -> item.getGuid().equals(importTaskVO.getFileGuid())).findFirst().orElse(null);
- importTaskVO.setSystemFile(systemFile);
- }
- if (importTaskVO.getImportContent() != null) {
- String icn = this.getImportContentStr(importTaskVO.getImportContent(), importTaskVO.getType());
- importTaskVO.setImportContentName(icn);
- }
- }
- }
- private String setImportTaskName(ImportTaskCondition importTaskCondition, String name) {
- //装载名称
- String type = "";
- String toName = "";
- String to = "";
- String taskName = "";
- if (importTaskCondition.getType().equals(2)) {
- type = "【专利号】";
- } else if (importTaskCondition.getType().equals(3) || importTaskCondition.getType().equals(4)) {
- type = "【检索式】";
- } else if (importTaskCondition.getType().equals(1)) {
- type = "【Excel】";
- }
- if (importTaskCondition.getProjectId() != null && importTaskCondition.getProjectType().equals(0)) {
- to = "专题库";
- LambdaQueryWrapper<Project> queryWrapper = new LambdaQueryWrapper<>();
- queryWrapper.in(Project::getId, importTaskCondition.getProjectId());
- List<Project> projects = projectService.list(queryWrapper);
- if (projects.size() != 0) {
- toName = projects.get(0).getName();
- }
- } else if (importTaskCondition.getProjectId() != null && importTaskCondition.getProjectType().equals(1)) {
- to = "报告";
- LambdaQueryWrapper<Project> queryWrapper = new LambdaQueryWrapper<>();
- queryWrapper.in(Project::getId, importTaskCondition.getProjectId());
- List<Project> projects = projectService.list(queryWrapper);
- if (projects.size() != 0) {
- toName = projects.get(0).getName();
- }
- } else if (importTaskCondition.getProductId() != null) {
- to = "产品";
- LambdaQueryWrapper<Product> queryWrapper = new LambdaQueryWrapper<>();
- queryWrapper.in(Product::getId, importTaskCondition.getProductId());
- List<Product> products = productService.list(queryWrapper);
- if (products.size() != 0) {
- toName = products.get(0).getName();
- }
- }
- //导入任务
- taskName = type + "导入到" + to + "【" + toName + "】 - " + name;
- return taskName;
- }
- public void updateImportTaskState(Integer taskId, Integer state) {
- ImportTask importTask = this.getById(taskId);
- importTask.setState(state);
- importTask.updateById();
- if (state.equals(4) || state.equals(5)) {
- schedulingTaskService.pauseTask(taskId, state);
- }
- if (state.equals(0)) {
- schedulingTaskService.startTask();
- }
- }
- public Integer addExportTask(ExportTaskDTO exportTaskDTO) {
- if (exportTaskDTO == null) {
- throw new XiaoShiException("入参不能为空");
- }
- ImportTaskCondition importTaskCondition = new ImportTaskCondition();
- if (exportTaskDTO.getProjectId() != null) {
- importTaskCondition.setProjectId(exportTaskDTO.getProjectId());
- }
- importTaskCondition.setIfUpdate(false);
- importTaskCondition.setType(exportTaskDTO.getType());
- importTaskCondition.setCreateId(exportTaskDTO.getCreateId());
- importTaskCondition.insert();
- Integer importTaskConditionId = importTaskCondition.getId();
- if (importTaskConditionId != null) {
- ImportTask importTask = new ImportTask();
- importTask.setImportTaskConditionId(importTaskConditionId);
- //设置任务的类型 6导出excel 7导出pdf首页
- importTask.setType(exportTaskDTO.getType());
- importTask.setAllNum(exportTaskDTO.getAllNum());
- importTask.setFinishTime(exportTaskDTO.getFinishTime());
- importTask.setState(0);
- importTask.setCreateId(exportTaskDTO.getCreateId());
- String name = "";
- if (exportTaskDTO.getType().equals(6)) {
- name = "【专利】";
- } else if (exportTaskDTO.getType().equals(7)) {
- name = "【PDF首页】";
- }
- String importTaskName = "导出" + name + "-" + exportTaskDTO.getCreateName();
- importTask.setName(importTaskName);
- importTask.insert();
- return importTask.getId();
- } else {
- throw new XiaoShiException("导出任务记录失败");
- }
- }
- public Integer updateExportTask(ExportTaskDTO exportTaskDTO) {
- if (exportTaskDTO == null) {
- throw new XiaoShiException("入参不能为空");
- }
- ImportTask importTask = this.getById(exportTaskDTO.getTaskId());
- if (importTask != null) {
- Integer importTaskConditionId = importTask.getImportTaskConditionId();
- ImportTaskCondition importTaskCondition = importTaskConditionService.getById(importTaskConditionId);
- importTaskCondition.setFileGuid(exportTaskDTO.getFileGuid());
- importTaskCondition.updateById();
- importTask.setState(exportTaskDTO.getState());
- if (exportTaskDTO.getAllNum() != null) {
- importTask.setAllNum(exportTaskDTO.getAllNum());
- }
- importTask.setDoneNum(exportTaskDTO.getDoneNum());
- if (exportTaskDTO.getDefaultNum() != null) {
- importTask.setDefaultNum(exportTaskDTO.getDefaultNum());
- }
- if (exportTaskDTO.getDoneNum() != null) {
- importTask.setDoneNum(exportTaskDTO.getDoneNum());
- }
- importTask.setFinishTime(exportTaskDTO.getFinishTime());
- importTask.updateById();
- }
- return importTask.getId();
- }
- //装载查询语句
- private List<String> loadSearchSql(List<String> sqls, Integer projectId) {
- PersonnelVO personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
- String id = personnelVO.getId();
- String rootSql = "";
- if (sqls.get(0) == null || projectId == null) {
- rootSql = "it.create_id=" + id;
- } else {
- Project project = projectService.getById(projectId);
- if (project == null) {
- throw new XiaoShiException("未查询到专题库");
- }
- String createId = project.getCreateId();
- String headId = project.getHeadId();
- if (createId != id && headId != id) {
- rootSql = "it.create_id=" + id;
- }
- }
- if (sqls.get(0) != null && !sqls.get(0).equals("") && !rootSql.equals("")) {
- sqls.set(0, rootSql + " and " + "(" + sqls.get(0) + ")");
- } else if ((sqls.get(0) == null || sqls.get(0).equals("")) && !rootSql.equals("")) {
- sqls.set(0, rootSql);
- }
- return sqls;
- }
- public Integer addPdfTask(AddImportPDFTaskDTO addImportPDFTaskDTO) {
- String fileGuid = addImportPDFTaskDTO.getFileGuid();
- Integer pdfType = addImportPDFTaskDTO.getPdfType();
- String remark = addImportPDFTaskDTO.getRemark();
- ImportTaskCondition importTaskCondition = new ImportTaskCondition();
- importTaskCondition.setFileGuid(fileGuid);
- importTaskCondition.setType(5);
- importTaskCondition.setPdfType(pdfType);
- importTaskCondition.setCreateId("1");
- importTaskCondition.insert();
- ImportTask importTask = new ImportTask();
- importTask.setImportTaskConditionId(importTaskCondition.getId());
- importTask.setRemark(remark);
- importTask.setCreateId("1");
- importTask.setType(5);
- importTask.insert();
- schedulingTaskService.startTask();
- return importTask.getId();
- }
- public void addImportTaskByCondition(ImportTaskCondition importTaskCondition, PatentProject project) {
- String condition = importTaskCondition.getSearchCondition();
- String updateCycle = project.getUpdateCycle();
- String dbType = importTaskCondition.getDbType();
- if (updateCycle == null) {
- return;
- }
- LocalDate localDate = LocalDate.now();
- List<String> dateRange = new ArrayList<>();
- switch (updateCycle) {
- case Cycle.WEEK:
- LocalDate localDateWeek = null;
- if (dbType != null && dbType.equals("CN")) {
- localDateWeek = localDate.minusWeeks(1);
- } else {
- localDateWeek = localDate.minusMonths(1).minusWeeks(1);
- }
- dateRange = DateUtils2.getWeekRange(localDateWeek);
- break;
- case Cycle.MONTH:
- LocalDate localDateMonth = null;
- if (dbType != null && dbType.equals("CN")) {
- localDateMonth = localDate.minusMonths(1);
- } else {
- localDateMonth = localDate.minusMonths(2);
- }
- dateRange = DateUtils2.getMonthRange(localDateMonth);
- break;
- case Cycle.QUARTER:
- LocalDate localDateQuartz = null;
- if (dbType != null && dbType.equals("CN")) {
- localDateQuartz = localDate.minusMonths(4);
- } else {
- localDateQuartz = localDate.minusMonths(5);
- }
- dateRange = DateUtils2.getQuartzRange(localDateQuartz);
- break;
- case Cycle.YEAR:
- LocalDate localYear = null;
- if (dbType != null && dbType.equals("CN")) {
- localYear = localDate.minusMonths(1).minusYears(1);
- } else {
- localYear= localDate.minusYears(1);
- }
- dateRange = DateUtils2.getYearRange(localYear);
- break;
- }
- if (dateRange.size() < 2) {
- return;
- }
- Date start = DateUtils.strToDate(dateRange.get(0));
- Date end = DateUtils.strToDate((dateRange.get(1)));
- LambdaQueryWrapper<ImportTask> queryWrapper = new LambdaQueryWrapper<>();
- queryWrapper.eq(ImportTask::getImportTaskConditionId, importTaskCondition.getId())
- .eq(ImportTask::getUpdateToDate, end)
- .eq(ImportTask::getLastUpdateToDate, start);
- ImportTask lastImportTask = this.getOne(queryWrapper, false);
- if (lastImportTask != null) {
- return;
- }
- ImportTask importTask = new ImportTask();
- String fromDateStr = DateUtils2.dateTimeToPatentStr(start);
- String todateStr = DateUtils2.dateTimeToPatentStr(end);
- importTask.setLastUpdateToDate(start);
- importTask.setUpdateToDate(end);
- if (dbType != null && dbType.equals("CN")) {
- condition = condition + " and (PD=" + fromDateStr + "~" + todateStr + " or GD=" + fromDateStr + "~" + todateStr + ")";
- } else {
- condition = condition + " and (PD=" + fromDateStr + "~" + todateStr + " or GD=" + fromDateStr + "~" + todateStr + ")";
- }
- PatentStarListDTO patentStarListDto = new PatentStarListDTO()
- .setCurrentQuery(condition)
- .setPageNum(1)
- .setRowCount(10)
- .setDBType(importTaskCondition.getDbType());
- //调用一般接口返回一批专利著录相关数据
- try {
- Map<String, Object> resultMap = patentStarApiService.patentStarSearchApi(patentStarListDto);
- if (resultMap == null) {
- importTask.setAllNum(-1);
- } else {
- importTask.setAllNum((Integer) resultMap.get("total"));
- }
- } catch (Exception e) {
- importTask.setAllNum(-1);
- e.printStackTrace();
- }
- importTask.setImportTaskConditionId(importTaskCondition.getId());
- importTask.setType(importTaskCondition.getType());
- importTask.setSearchCondition(condition);
- importTask.setCreateId(importTaskCondition.getCreateId());
- importTask.setIfCreateBySys(true);
- if (importTask.getAllNum() != null && importTask.getAllNum() <= 0) {
- importTask.setState(2);
- mailSendService.sendCycleImportTaskDoneEmail(importTask);
- importTask.insert();
- } else {
- importTask.insert();
- schedulingTaskService.startTask();
- }
- }
- public String getImportContentStr(Integer importContent, Integer taskType) {
- List<String> contents = new ArrayList<>();
- String imContents = "0000";
- //当任务为excel导入
- if (taskType.equals(1)) {
- imContents = "1100";
- }
- //当任务为pdf导入
- else if (taskType.equals(5)) {
- imContents = "0001";
- } else if (!importContent.equals(0)) {
- imContents = MathUtils.fun(2, importContent);
- }
- //下载字段
- char[] importCells = imContents.toCharArray();
- char ifCataloguing = importCells[0];
- char ifAddPicture = importCells[1];
- char ifFullText = importCells[2];
- char ifPdf = importCells[3];
- if (ifCataloguing == '1') {
- contents.add("著录信息");
- }
- if (ifAddPicture == '1') {
- contents.add("摘要附图");
- }
- if (ifFullText == '1') {
- contents.add("权要或说明书");
- }
- if (ifPdf == '1') {
- contents.add("pdf或外观附图");
- }
- String contentStr = "";
- if (contents.size() > 0) {
- contentStr = StringUtils.join(contents, " ");
- }
- return contentStr;
- }
- }
|