|
@@ -0,0 +1,134 @@
|
|
|
+package org.springblade.land.service.impl;
|
|
|
+
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import net.bytebuddy.asm.Advice;
|
|
|
+import org.springblade.common.utils.SnowFlakeUtil;
|
|
|
+import org.springblade.core.log.exception.ServiceException;
|
|
|
+import org.springblade.core.mp.base.BaseServiceImpl;
|
|
|
+import org.springblade.core.mp.support.Query;
|
|
|
+import org.springblade.core.oss.model.BladeFile;
|
|
|
+import org.springblade.core.tool.utils.Func;
|
|
|
+import org.springblade.core.tool.utils.ResourceUtil;
|
|
|
+import org.springblade.land.dto.PolicyInfoDTO;
|
|
|
+import org.springblade.land.dto.PolicyInfoSearchDTO;
|
|
|
+import org.springblade.land.entity.AttachmentInfo;
|
|
|
+import org.springblade.land.entity.PolicyInfo;
|
|
|
+import org.springblade.land.mapper.PolicyInfoMapper;
|
|
|
+import org.springblade.land.service.IAttachmentInfoService;
|
|
|
+import org.springblade.land.service.IPolicyInfoService;
|
|
|
+import org.springblade.land.utils.FileUtils;
|
|
|
+import org.springblade.resource.feign.NewIOSSClient;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileNotFoundException;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+@Service
|
|
|
+@AllArgsConstructor
|
|
|
+public class PolicyInfoServiceImpl extends BaseServiceImpl<PolicyInfoMapper, PolicyInfo> implements IPolicyInfoService {
|
|
|
+
|
|
|
+ private final IAttachmentInfoService attachmentInfoService;
|
|
|
+
|
|
|
+ private final NewIOSSClient newIOSSClient;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增法律法规
|
|
|
+ * @param dto
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public void add(PolicyInfoDTO dto) throws FileNotFoundException {
|
|
|
+ String file_path = FileUtils.getSysLocalFileUrl();
|
|
|
+ PolicyInfo policyInfo = new PolicyInfo();
|
|
|
+ BeanUtils.copyProperties(dto,policyInfo);
|
|
|
+ Boolean isExist = true;
|
|
|
+ if (policyInfo.getId() == null){
|
|
|
+ isExist = false;
|
|
|
+ policyInfo.setId(SnowFlakeUtil.getId());
|
|
|
+ policyInfo.setUploadDate(LocalDate.now());
|
|
|
+ //删除之前的附件
|
|
|
+ attachmentInfoService.deleteByMasterId(-1L);
|
|
|
+ }else {
|
|
|
+ //删除之前的附件
|
|
|
+ attachmentInfoService.deleteByMasterId(policyInfo.getId());
|
|
|
+ }
|
|
|
+ List<AttachmentInfo> list = dto.getList();
|
|
|
+ if (list == null || list.size() == 0){
|
|
|
+ throw new ServiceException("请上传附件");
|
|
|
+ }
|
|
|
+ List<String> data = new ArrayList<>();
|
|
|
+ for (AttachmentInfo info : list) {
|
|
|
+ info.setMasterId(policyInfo.getId());
|
|
|
+ data.add(info.getDomainPdfUrl());
|
|
|
+ }
|
|
|
+ if (data.size() < 1){
|
|
|
+ throw new ServiceException("附件信息错误");
|
|
|
+ }
|
|
|
+ String listPdf = file_path + "/pdf/" + policyInfo.getId() + ".pdf";
|
|
|
+ File pdf2 = ResourceUtil.getFile(listPdf);
|
|
|
+ if (pdf2.exists()) {
|
|
|
+ pdf2.delete();
|
|
|
+ }
|
|
|
+ //pdf合并
|
|
|
+ FileUtils.mergePdfPublicMethods(data, listPdf);
|
|
|
+ BladeFile bladeFile = this.newIOSSClient.uploadFile( policyInfo.getId() + ".pdf", listPdf);
|
|
|
+ policyInfo.setPdfUrl(bladeFile.getLink());
|
|
|
+ if (isExist){
|
|
|
+ this.updateById(policyInfo);
|
|
|
+ }else {
|
|
|
+ this.save(policyInfo);
|
|
|
+ }
|
|
|
+ //修改附件的主件id
|
|
|
+ attachmentInfoService.saveBatch(list);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页查询
|
|
|
+ * @param page
|
|
|
+ * @param dto
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public IPage<PolicyInfo> page(Query page, PolicyInfoSearchDTO dto) {
|
|
|
+ IPage<PolicyInfo> iPage = new Page<>(page.getCurrent(),page.getSize());
|
|
|
+ return baseMapper.page(iPage,dto);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量删除
|
|
|
+ * @param ids
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void remove(List<Long> ids) {
|
|
|
+ //删除附件
|
|
|
+ attachmentInfoService.deleteByMasterIds(ids);
|
|
|
+ //删除主件
|
|
|
+ baseMapper.deleteBatchIds(ids);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据id查询
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public PolicyInfoDTO detail(Long id) {
|
|
|
+ PolicyInfoDTO dto = new PolicyInfoDTO();
|
|
|
+ PolicyInfo info = this.getById(id);
|
|
|
+ BeanUtils.copyProperties(info,dto);
|
|
|
+ List<AttachmentInfo> list = attachmentInfoService.getAllFile(id);
|
|
|
+ dto.setList(list);
|
|
|
+ return dto;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|