|
@@ -9,8 +9,9 @@ import org.apache.commons.lang.StringUtils;
|
|
|
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.mapper.ExMInvoiceMapper;
|
|
|
import org.springblade.control.service.EMInvoiceService;
|
|
|
+import org.springblade.control.utils.BuildSerialUtils;
|
|
|
import org.springblade.control.vo.EMDraftVO;
|
|
|
import org.springblade.control.vo.EMInvoiceInfoVO;
|
|
|
import org.springblade.core.log.exception.ServiceException;
|
|
@@ -25,27 +26,23 @@ import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
-import java.io.IOException;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
@AllArgsConstructor
|
|
|
-public class EMInvoiceServiceImpl extends BaseServiceImpl<EMInvoiceMapper, EMInvoiceInfo> implements EMInvoiceService {
|
|
|
+public class EMInvoiceServiceImpl extends BaseServiceImpl<ExMInvoiceMapper, 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::getIsTemp, 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));
|
|
@@ -54,7 +51,7 @@ public class EMInvoiceServiceImpl extends BaseServiceImpl<EMInvoiceMapper, EMInv
|
|
|
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("已审批") ? "已通过" : "未通过");
|
|
|
+ vo.setApprovalResultName(vo.getApprovalStatusName().equals("已审批") || vo.getApprovalStatusName().equals("已驳回") ? "已通过" : "未通过");
|
|
|
for (DictInfo dictInfo : dictInfoList1) {
|
|
|
if (dictInfo.getDictValue().equals(vo.getInvoiceType() + "")) {
|
|
|
vo.setInvoiceTypeName(dictInfo.getDictName());
|
|
@@ -81,14 +78,14 @@ public class EMInvoiceServiceImpl extends BaseServiceImpl<EMInvoiceMapper, EMInv
|
|
|
//计算三个月前的时间
|
|
|
LocalDateTime threeMonthsAgo = now.minusMonths(3);
|
|
|
queryWrapper.between(EMInvoiceInfo::getCreateTime, threeMonthsAgo, now);
|
|
|
- queryWrapper.eq(EMInvoiceInfo::getIsDeleted, 1); //暂存
|
|
|
+ queryWrapper.eq(EMInvoiceInfo::getIsTemp, 0); //暂存
|
|
|
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() + "提交的开票申请" : ""));
|
|
|
+ userMaps.get(obj.getCreateUser()).stream().findAny().ifPresent(user -> vo.setTitle((ObjectUtil.isNotEmpty(user) && ObjectUtil.isNotEmpty(user.getRealName())) ? user.getRealName() + "提交的开票申请" : ""));
|
|
|
vo.setUpdateTime(obj.getUpdateTime());
|
|
|
resultVOS.add(vo);
|
|
|
}
|
|
@@ -107,21 +104,51 @@ public class EMInvoiceServiceImpl extends BaseServiceImpl<EMInvoiceMapper, EMInv
|
|
|
|
|
|
@Override
|
|
|
public boolean invoiceSubmit(EMInvoiceInfoDTO dto) {
|
|
|
+ if (ObjectUtil.isEmpty(SecureUtil.getUser())) {
|
|
|
+ throw new ServiceException("获取当前用户信息失败,请联系管理员");
|
|
|
+ }
|
|
|
+ boolean var = false;
|
|
|
+ dto.setCreateUser(SecureUtil.getUserId());
|
|
|
+
|
|
|
if (("1").equals(dto.getSubmitStatus())) {
|
|
|
- dto.setIsDeleted(1); //暂存
|
|
|
+ if (ObjectUtil.isEmpty(dto.getId()) && ObjectUtil.isEmpty(dto.getInvoiceNumber())) {
|
|
|
+ dto.setInvoiceNumber(this.getNumber());
|
|
|
+ } else if (ObjectUtil.isNotEmpty(dto.getId())) {
|
|
|
+ EMInvoiceInfo obj = baseMapper.selectById(dto.getId());
|
|
|
+ if (obj != null && obj.getStatus() == 3) {
|
|
|
+ //如果是已驳回任务,那么重新生成新的记录信息
|
|
|
+ dto.setId(SnowFlakeUtil.getId());
|
|
|
+ dto.setInvoiceNumber(this.getNumber());
|
|
|
+ var = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ dto.setIsTemp(0); //暂存
|
|
|
dto.setStatus(0); //未上报
|
|
|
- this.saveOrUpdate(dto);
|
|
|
+ if (var) {
|
|
|
+ this.save(dto);
|
|
|
+ } else {
|
|
|
+ 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.getId())) {
|
|
|
+ EMInvoiceInfo obj = baseMapper.selectById(dto.getId());
|
|
|
+ if (obj != null && (obj.getStatus() != 0 && obj.getStatus() != 3)) {
|
|
|
+ throw new ServiceException("当前填报的信息不是未上报、已驳回状态,不允许操作!");
|
|
|
+ } else if (obj != null && obj.getStatus() == 3) {
|
|
|
+ //如果是已驳回任务,那么重新生成新的记录信息
|
|
|
+ dto.setId(SnowFlakeUtil.getId());
|
|
|
+ dto.setInvoiceNumber(this.getNumber());
|
|
|
+ var = true;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (ObjectUtil.isEmpty(dto.getInvoiceNumber())) {
|
|
|
+ dto.setInvoiceNumber(this.getNumber());
|
|
|
+ }
|
|
|
}
|
|
|
- if (ObjectUtil.isNotEmpty(dto.getResponsibleUser()) && ObjectUtil.isNotEmpty(dto.getFinanceUser()) && ObjectUtil.isNotEmpty(dto.getCcUserList())) {
|
|
|
+ if (ObjectUtil.isNotEmpty(dto.getResponsibleUser()) && ObjectUtil.isNotEmpty(dto.getFinanceUser())) {
|
|
|
//新增审批任务
|
|
|
- if (ObjectUtil.isEmpty(SecureUtil.getUserName())) {
|
|
|
- throw new ServiceException("获取当前用户信息失败,请联系管理员");
|
|
|
- }
|
|
|
TaskProcessInfo taskProcessInfo = new TaskProcessInfo();
|
|
|
taskProcessInfo.setId(SnowFlakeUtil.getId());
|
|
|
taskProcessInfo.setStatus(1); //待审批
|
|
@@ -140,17 +167,23 @@ public class EMInvoiceServiceImpl extends BaseServiceImpl<EMInvoiceMapper, EMInv
|
|
|
taskProcessInfo.setAuditUserIds(StringUtils.join(auditUserIds, ","));
|
|
|
|
|
|
//抄送人
|
|
|
- List<String> ccUserObjList = dto.getCcUserList().stream().map(EMProcessTaskUser::getUserId).collect(Collectors.toList());
|
|
|
- taskProcessInfo.setCcUserIds(StringUtils.join(ccUserObjList, ","));
|
|
|
+ if (ObjectUtil.isNotEmpty(dto.getCcUserList())) {
|
|
|
+ List<String> ccUserObjList = dto.getCcUserList().stream().map(EMProcessTaskUser::getUserId).collect(Collectors.toList());
|
|
|
+ taskProcessInfo.setCcUserIds(StringUtils.join(ccUserObjList, ","));
|
|
|
+ }
|
|
|
taskProcessService.save(taskProcessInfo);
|
|
|
|
|
|
//新增信息
|
|
|
- dto.setIsDeleted(0); //提交
|
|
|
+ dto.setIsTemp(1); //提交
|
|
|
dto.setStatus(1); //待审批
|
|
|
- this.saveOrUpdate(dto);
|
|
|
+ if (var) {
|
|
|
+ this.save(dto);
|
|
|
+ } else {
|
|
|
+ this.saveOrUpdate(dto);
|
|
|
+ }
|
|
|
|
|
|
//新增审批任务关联信息
|
|
|
- jdbcTemplate.execute("insert into c_expense_task_record(id,task_id,expense_info_id) values (" + SnowFlakeUtil.getId() + "," + taskProcessInfo.getId() + "," + dto.getId() + ")");
|
|
|
+ jdbcTemplate.execute("delete from c_expense_task_record where task_id = " + taskProcessInfo.getId() + " and expense_info_id = " + dto.getId() + " ; insert into c_expense_task_record(id,task_id,expense_info_id,expense_info_type) values (" + SnowFlakeUtil.getId() + "," + taskProcessInfo.getId() + "," + dto.getId() + ",7)");
|
|
|
|
|
|
//存储关联项目id,审批闭环后处理项目相关业务 TODO
|
|
|
|
|
@@ -173,16 +206,18 @@ public class EMInvoiceServiceImpl extends BaseServiceImpl<EMInvoiceMapper, EMInv
|
|
|
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());
|
|
|
+ List<ExpenseTaskRecord> records = jdbcTemplate.query("select * from c_expense_task_record where expense_info_id = " + id, new BeanPropertyRowMapper<>(ExpenseTaskRecord.class));
|
|
|
+ if (records.size() > 0) {
|
|
|
+ for (ExpenseTaskRecord record : records) {
|
|
|
+ //删除上报的审批任务
|
|
|
+ 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));
|
|
|
+ this.update(Wrappers.<EMInvoiceInfo>lambdaUpdate().set(EMInvoiceInfo::getStatus, 0).set(EMInvoiceInfo::getIsTemp, 0).eq(EMInvoiceInfo::getId, id));
|
|
|
|
|
|
return true;
|
|
|
}
|
|
@@ -191,58 +226,18 @@ public class EMInvoiceServiceImpl extends BaseServiceImpl<EMInvoiceMapper, EMInv
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public boolean invoiceUpload(Long id, MultipartFile file) throws IOException {
|
|
|
+ public boolean invoiceUpload(Long id, String pdfUrl) {
|
|
|
+ if (StringUtils.isNotEmpty(pdfUrl)) {
|
|
|
+ throw new ServiceException("未获取到当前pdf路径信息,上传失败!");
|
|
|
+ }
|
|
|
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;
|
|
|
- }*/
|
|
|
+ //修改pdf路径
|
|
|
+ this.update(Wrappers.<EMInvoiceInfo>lambdaUpdate().set(EMInvoiceInfo::getInvoicePdfUrl, pdfUrl).eq(EMInvoiceInfo::getId, id));
|
|
|
+ return true;
|
|
|
} else {
|
|
|
- throw new ServiceException("当前发票记录信息不是已审批通过状态,无法上传!");
|
|
|
+ throw new ServiceException("当前发票记录信息不是已审批通过状态,上传失败!");
|
|
|
}
|
|
|
- return false;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -254,4 +249,27 @@ public class EMInvoiceServiceImpl extends BaseServiceImpl<EMInvoiceMapper, EMInv
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取编号
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private String getNumber() {
|
|
|
+ List<EMInvoiceInfo> emFinancialReimbursementInfos = baseMapper.selectList(Wrappers.<EMInvoiceInfo>lambdaQuery().select(EMInvoiceInfo::getInvoiceNumber).isNotNull(EMInvoiceInfo::getInvoiceNumber));
|
|
|
+ Set<Integer> numberSet = new HashSet<>();
|
|
|
+ for (EMInvoiceInfo obj : emFinancialReimbursementInfos) {
|
|
|
+ String number = obj.getInvoiceNumber().split("-")[1];
|
|
|
+ numberSet.add(Integer.parseInt(number));
|
|
|
+ }
|
|
|
+
|
|
|
+ int maxValue = Integer.MIN_VALUE;
|
|
|
+ for (int value : numberSet) {
|
|
|
+ if (value > maxValue) {
|
|
|
+ maxValue = value;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return "FP-" + BuildSerialUtils.buildSerial((maxValue + 1), 4);
|
|
|
+ }
|
|
|
+
|
|
|
}
|