|
@@ -0,0 +1,267 @@
|
|
|
+package org.springblade.control.service.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import lombok.Data;
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
+import org.apache.pdfbox.pdmodel.PDDocument;
|
|
|
+import org.springblade.common.utils.SnowFlakeUtil;
|
|
|
+import org.springblade.control.dto.EMInvoiceInfoDTO;
|
|
|
+import org.springblade.control.entity.*;
|
|
|
+import org.springblade.control.mapper.EMInvoiceMapper;
|
|
|
+import org.springblade.control.service.EMInvoiceService;
|
|
|
+import org.springblade.control.vo.EMDraftVO;
|
|
|
+import org.springblade.control.vo.EMInvoiceInfoVO;
|
|
|
+import org.springblade.core.log.exception.ServiceException;
|
|
|
+import org.springblade.core.mp.base.BaseServiceImpl;
|
|
|
+import org.springblade.core.mp.support.Condition;
|
|
|
+import org.springblade.core.oss.model.BladeFile;
|
|
|
+import org.springblade.core.secure.utils.SecureUtil;
|
|
|
+import org.springblade.core.tool.utils.BeanUtil;
|
|
|
+import org.springblade.core.tool.utils.FileUtil;
|
|
|
+import org.springblade.core.tool.utils.ObjectUtil;
|
|
|
+import org.springblade.resource.builder.oss.OssBuilder;
|
|
|
+import org.springblade.resource.entity.Attach;
|
|
|
+import org.springblade.resource.feign.CommonFileClient;
|
|
|
+import org.springblade.resource.service.IAttachService;
|
|
|
+import org.springblade.resource.vo.NewBladeFile;
|
|
|
+import org.springblade.system.user.entity.User;
|
|
|
+import org.springblade.system.user.feign.IUserClient;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
|
+import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import java.io.ByteArrayInputStream;
|
|
|
+import java.io.IOException;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+@Data
|
|
|
+@AllArgsConstructor
|
|
|
+public class EMInvoiceServiceImpl extends BaseServiceImpl<EMInvoiceMapper, EMInvoiceInfo> implements EMInvoiceService {
|
|
|
+
|
|
|
+ private final IUserClient iUserClient;
|
|
|
+ private final JdbcTemplate jdbcTemplate;
|
|
|
+ private final OssBuilder ossBuilder;
|
|
|
+ private final CommonFileClient commonFileClient;
|
|
|
+ private final IAttachService attachService;
|
|
|
+ private final TaskProcessServiceImpl taskProcessService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public IPage<EMInvoiceInfoVO> invoicePage(IPage<EMInvoiceInfo> page, EMInvoiceInfoDTO dto) {
|
|
|
+ QueryWrapper<EMInvoiceInfo> queryWrapper = Condition.getQueryWrapper(dto);
|
|
|
+ queryWrapper.lambda().eq(EMInvoiceInfo::getIsDeleted, 1);
|
|
|
+ IPage<EMInvoiceInfo> pages = this.page(page, queryWrapper.lambda().orderBy(true, true, EMInvoiceInfo::getCreateTime));
|
|
|
+ Map<Long, String> userMap = iUserClient.selectUserAll().stream().collect(Collectors.toMap(User::getId, User::getRealName));
|
|
|
+ List<DictInfo> dictInfoList1 = jdbcTemplate.query("select dict_name,dict_value from c_dict_info where code = 'invoice_type'", new BeanPropertyRowMapper<>(DictInfo.class));
|
|
|
+ return pages.convert(obj -> {
|
|
|
+ EMInvoiceInfoVO vo = new EMInvoiceInfoVO();
|
|
|
+ BeanUtils.copyProperties(obj, vo);
|
|
|
+ vo.setCreateName(userMap.get(vo.getCreateUser()));
|
|
|
+ vo.setApprovalStatusName(vo.getStatus().equals(1) ? "待审批" : (vo.getStatus().equals(2) ? "已审批" : (vo.getStatus().equals(3) ? "已驳回" : "未上报")));
|
|
|
+ vo.setApprovalResultName(vo.getApprovalStatusName().equals("已审批") ? "已通过" : "未通过");
|
|
|
+ for (DictInfo dictInfo : dictInfoList1) {
|
|
|
+ if (dictInfo.getDictValue().equals(vo.getInvoiceType() + "")) {
|
|
|
+ vo.setInvoiceTypeName(dictInfo.getDictName());
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ vo.setInvoiceContentType(null); //发票内容字典type TODO
|
|
|
+ vo.setProjectName(""); //关联项目名 TODO
|
|
|
+
|
|
|
+ return vo;
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<EMDraftVO> invoiceDraftList() {
|
|
|
+ if (ObjectUtil.isEmpty(SecureUtil.getUserId())) {
|
|
|
+ throw new ServiceException("获取当前用户信息失败,请联系管理员");
|
|
|
+ }
|
|
|
+ LambdaQueryWrapper<EMInvoiceInfo> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(EMInvoiceInfo::getCreateUser, SecureUtil.getUserId()); //获取当前用户草稿信息
|
|
|
+ //获取当前时间
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
+ //计算三个月前的时间
|
|
|
+ LocalDateTime threeMonthsAgo = now.minusMonths(3);
|
|
|
+ queryWrapper.between(EMInvoiceInfo::getCreateTime, threeMonthsAgo, now);
|
|
|
+ queryWrapper.eq(EMInvoiceInfo::getIsDeleted, 1); //暂存
|
|
|
+ List<EMInvoiceInfo> list = baseMapper.selectList(queryWrapper);
|
|
|
+ Map<Long, List<User>> userMaps = iUserClient.selectUserAll().stream().collect(Collectors.groupingBy(User::getId));
|
|
|
+ List<EMDraftVO> resultVOS = new ArrayList<>();
|
|
|
+ for (EMInvoiceInfo obj : list) {
|
|
|
+ EMDraftVO vo = new EMDraftVO();
|
|
|
+ vo.setId(obj.getId());
|
|
|
+ userMaps.get(obj.getCreateUser()).stream().findAny().ifPresent(user -> vo.setTitle((ObjectUtil.isNotEmpty(user) && ObjectUtil.isNotEmpty(user.getRealName())) ? user.getRealName() + obj.getCreateUser() + "提交的开票申请" : ""));
|
|
|
+ vo.setUpdateTime(obj.getUpdateTime());
|
|
|
+ resultVOS.add(vo);
|
|
|
+ }
|
|
|
+ return resultVOS.stream()
|
|
|
+ .sorted(Comparator.comparing(EMDraftVO::getUpdateTime).reversed())
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public EMInvoiceInfoVO invoiceDetail(Long id) {
|
|
|
+ EMInvoiceInfo obj = baseMapper.selectById(id);
|
|
|
+ EMInvoiceInfoVO vo = BeanUtil.copyProperties(obj, EMInvoiceInfoVO.class);
|
|
|
+ //TODO vo.set
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean invoiceSubmit(EMInvoiceInfoDTO dto) {
|
|
|
+ if (("1").equals(dto.getSubmitStatus())) {
|
|
|
+ dto.setIsDeleted(1); //暂存
|
|
|
+ dto.setStatus(0); //未上报
|
|
|
+ this.saveOrUpdate(dto);
|
|
|
+ return true;
|
|
|
+
|
|
|
+ } else if (("2").equals(dto.getSubmitStatus())) { //提交审批
|
|
|
+ if (ObjectUtil.isNotEmpty(dto.getId()) && !new Integer(0).equals(dto.getStatus())) {
|
|
|
+ throw new ServiceException("当前填报的信息不是未上报状态,不允许操作!");
|
|
|
+ }
|
|
|
+ if (ObjectUtil.isNotEmpty(dto.getResponsibleUser()) && ObjectUtil.isNotEmpty(dto.getFinanceUser()) && ObjectUtil.isNotEmpty(dto.getCcUserList())) {
|
|
|
+ //新增审批任务
|
|
|
+ if (ObjectUtil.isEmpty(SecureUtil.getUserName())) {
|
|
|
+ throw new ServiceException("获取当前用户信息失败,请联系管理员");
|
|
|
+ }
|
|
|
+ TaskProcessInfo taskProcessInfo = new TaskProcessInfo();
|
|
|
+ taskProcessInfo.setId(SnowFlakeUtil.getId());
|
|
|
+ taskProcessInfo.setStatus(1); //待审批
|
|
|
+ taskProcessInfo.setReportDate(new Date());
|
|
|
+ taskProcessInfo.setTaskType(7); //发票审批
|
|
|
+ taskProcessInfo.setTaskName("【" + SecureUtil.getUserName() + "】向您发起【发票审批】审批");
|
|
|
+ //上报人
|
|
|
+ taskProcessInfo.setReportUserId(SecureUtil.getUserId());
|
|
|
+
|
|
|
+ //审批人
|
|
|
+ List<String> auditUserIds = new LinkedList<>();
|
|
|
+ EMProcessTaskUser responsibleObj = dto.getResponsibleUser(); //部门负责人
|
|
|
+ auditUserIds.add(responsibleObj.getUserId());
|
|
|
+ EMProcessTaskUser financeObj = dto.getFinanceUser(); //财务
|
|
|
+ auditUserIds.add(financeObj.getUserId());
|
|
|
+ taskProcessInfo.setAuditUserIds(StringUtils.join(auditUserIds, ","));
|
|
|
+
|
|
|
+ //抄送人
|
|
|
+ List<String> ccUserObjList = dto.getCcUserList().stream().map(EMProcessTaskUser::getUserId).collect(Collectors.toList());
|
|
|
+ taskProcessInfo.setCcUserIds(StringUtils.join(ccUserObjList, ","));
|
|
|
+ taskProcessService.save(taskProcessInfo);
|
|
|
+
|
|
|
+ //新增信息
|
|
|
+ dto.setIsDeleted(0); //提交
|
|
|
+ dto.setStatus(1); //待审批
|
|
|
+ this.saveOrUpdate(dto);
|
|
|
+
|
|
|
+ //新增审批任务关联信息
|
|
|
+ jdbcTemplate.execute("insert into c_expense_task_record(id,task_id,expense_info_id) values (" + SnowFlakeUtil.getId() + "," + taskProcessInfo.getId() + "," + dto.getId() + ")");
|
|
|
+
|
|
|
+ //存储关联项目id,审批闭环后处理项目相关业务 TODO
|
|
|
+
|
|
|
+ return true;
|
|
|
+
|
|
|
+ } else {
|
|
|
+ throw new ServiceException("获取当前审批流程人员信息失败,请联系管理员");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean invoiceRemove(Long id) {
|
|
|
+ return this.removeById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean invoiceCancel(Long id) {
|
|
|
+ EMInvoiceInfo obj = baseMapper.selectById(id);
|
|
|
+ if (obj != null && obj.getStatus().equals(1)) {
|
|
|
+ //查询记录任务关联信息
|
|
|
+ ExpenseTaskRecord record = jdbcTemplate.query("select * from c_expense_task_record where expense_info_id = " + id, new BeanPropertyRowMapper<>(ExpenseTaskRecord.class)).stream().findAny().orElse(null);
|
|
|
+ if (record != null) {
|
|
|
+ //删除上报的审批任务
|
|
|
+ jdbcTemplate.execute("delete from c_task_process_info where id = " + record.getTaskId());
|
|
|
+
|
|
|
+ //删除记录任务关联信息
|
|
|
+ jdbcTemplate.execute("delete from c_expense_task_record where expense_info_id = " + id + " and task_id = " + record.getTaskId());
|
|
|
+
|
|
|
+ //修改当前记录为未上报状态,且暂存
|
|
|
+ this.update(Wrappers.<EMInvoiceInfo>lambdaUpdate().set(EMInvoiceInfo::getStatus, 0).set(EMInvoiceInfo::getIsDeleted, 1).eq(EMInvoiceInfo::getId, id));
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean invoiceUpload(Long id, MultipartFile file) throws IOException {
|
|
|
+ EMInvoiceInfo obj = baseMapper.selectById(id);
|
|
|
+ if (obj != null && obj.getStatus().equals(2)) { //已通过(已审批)
|
|
|
+ //上传原图
|
|
|
+ ByteArrayInputStream inputStream = new ByteArrayInputStream(file.getBytes());
|
|
|
+ BladeFile bladeFile = ossBuilder.template().putFile(file.getOriginalFilename(), inputStream);
|
|
|
+
|
|
|
+ //处理PDF文件
|
|
|
+ NewBladeFile newBladeFile = new NewBladeFile();
|
|
|
+ if (Objects.requireNonNull(file.getOriginalFilename()).contains("xlsx")) {
|
|
|
+ newBladeFile = this.commonFileClient.excelToPdf(file);
|
|
|
+
|
|
|
+ } else if (file.getOriginalFilename().contains("xls")) {
|
|
|
+ newBladeFile = this.commonFileClient.excelToPdf(file);
|
|
|
+
|
|
|
+ } else if (file.getOriginalFilename().contains("docx")) {
|
|
|
+ newBladeFile = this.commonFileClient.wordToPdf(file);
|
|
|
+
|
|
|
+ } else if (file.getOriginalFilename().contains("png") || file.getOriginalFilename().contains("jpg")) {
|
|
|
+ newBladeFile = this.commonFileClient.pngOrJpgToPdf(file);
|
|
|
+
|
|
|
+ } else if (file.getOriginalFilename().contains("pdf")) {
|
|
|
+ //获取PDF文件
|
|
|
+ PDDocument document = PDDocument.load(file.getInputStream());
|
|
|
+ //获取文件页数
|
|
|
+ newBladeFile.setPage(document.getPages().getCount());
|
|
|
+ //pdf的路径就是文件上传的路径
|
|
|
+ newBladeFile.setPdfUrl(bladeFile.getLink());
|
|
|
+ }
|
|
|
+
|
|
|
+ BeanUtils.copyProperties(bladeFile, newBladeFile);
|
|
|
+ newBladeFile.setFileSize(file.getSize() / 1024);
|
|
|
+
|
|
|
+ //入库
|
|
|
+ String fileExtension = FileUtil.getFileExtension(bladeFile.getOriginalName());
|
|
|
+ Attach attach = new Attach();
|
|
|
+ attach.setDomainUrl(bladeFile.getDomain());
|
|
|
+ attach.setLink(newBladeFile.getPdfUrl());
|
|
|
+ attach.setName(bladeFile.getName());
|
|
|
+ attach.setOriginalName(bladeFile.getOriginalName());
|
|
|
+ attach.setAttachSize(newBladeFile.getFileSize());
|
|
|
+ attach.setExtension(fileExtension);
|
|
|
+
|
|
|
+ if (attachService.save(attach)) {
|
|
|
+ //修改pdf路径
|
|
|
+ this.update(Wrappers.<EMInvoiceInfo>lambdaUpdate().set(EMInvoiceInfo::getInvoicePdfUrl, newBladeFile.getPdfUrl()).eq(EMInvoiceInfo::getId, id));
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new ServiceException("当前发票记录信息不是已审批通过状态,无法上传!");
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Object invoicePdf(Long id) {
|
|
|
+ EMInvoiceInfo obj = baseMapper.selectById(id);
|
|
|
+ if (obj != null && StringUtils.isNotEmpty(obj.getInvoicePdfUrl())) {
|
|
|
+ return obj.getInvoicePdfUrl();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|