feat:发票申请

This commit is contained in:
dzc committed 2025-07-04 10:39:50 +08:00
1 parent 285c05c2dd
commit 2f6bf9a2fb
7 files changed
+202 -8

No files matched your search

@@ -0,0 +1,15 @@
package com.bsd.pjcloud.wallet.api.dto.recharge;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
@Data
public class WalletRechargeInvoiceApplyDto {
@NotNull(message = "发票id不能为空")
private Long id;
@NotNull(message = "发票图片不能为空")
private String picUrl;
}
@@ -3,8 +3,7 @@ package com.bsd.pjcloud.wallet.api.entity.recharge;
import com.baomidou.mybatisplus.annotation.*;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.*;
import com.bsd.pjcloud.common.core.util.TenantTable;
import java.time.LocalDateTime;
@@ -12,6 +11,9 @@ import java.time.LocalDateTime;
/**
* 充值/扣款申请发票记录
*/
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Data
@TenantTable
@TableName("wallet_recharge_invoice")
@@ -99,18 +101,36 @@ public class WalletRechargeInvoiceEntity extends Model<WalletRechargeInvoiceEnti
@Schema(description = "状态")
private String status;
/**
* 发票审核状态
*/
// @Schema(description = "发票审核状态")
// private String invoiceStatus;
/**
* 发票图片地址(不盖章)
*/
@Schema(description = "发票图片地址(不盖章)")
private String picUrl;
/**
* 流程id
*/
@Schema(description = "流程id")
private String processId;
/**
* 流程状态
*/
@Schema(description = "流程状态")
private String processStatus;
/**
* 申请时间
*/
@Schema(description = "申请时间")
private LocalDateTime applyTime;
/**
* 审核时间
*/
@Schema(description = "审核时间")
private LocalDateTime processTime;
/**
* 创建人
*/
@@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bsd.pjcloud.common.core.util.R;
import com.bsd.pjcloud.common.data.datascope.DataScope;
import com.bsd.pjcloud.common.excel.annotation.RequestExcel;
import com.bsd.pjcloud.common.idempotent.annotation.Idempotent;
import com.bsd.pjcloud.common.log.annotation.SysLog;
import com.bsd.pjcloud.common.security.annotation.Inner;
import com.bsd.pjcloud.flow.task.dto.ProcessNodeRecordAssignUserParamDto;
@@ -150,11 +151,13 @@ public class WalletRechargeApplyController {
}
@PostMapping("/read-excel")
@Idempotent(expireTime = 3, info = "正在上传中,请勿重复操作")
public R readExcel(@RequestExcel List<WalletRechargeExcelDto> excelVOList, BindingResult bindingResult, @RequestParam(required = false) String bizType) {
return walletRechargeApplyService.readExcel(excelVOList, bindingResult, bizType);
}
@PostMapping("/read-topup-excel")
@Idempotent(expireTime = 3, info = "正在上传中,请勿重复操作")
public R readTopupExcel(@RequestExcel List<WalletRechargeExcelDto> excelVOList, BindingResult bindingResult) {
return walletRechargeApplyService.readTopupExcel(excelVOList, bindingResult);
}
@@ -6,8 +6,12 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bsd.pjcloud.common.core.util.R;
import com.bsd.pjcloud.common.data.datascope.DataScope;
import com.bsd.pjcloud.common.idempotent.annotation.Idempotent;
import com.bsd.pjcloud.common.log.annotation.SysLog;
import com.bsd.pjcloud.common.security.annotation.Inner;
import com.bsd.pjcloud.flow.task.dto.ProcessNodeRecordAssignUserParamDto;
import com.bsd.pjcloud.wallet.api.dto.recharge.WalletRechargeBindInvoiceDto;
import com.bsd.pjcloud.wallet.api.dto.recharge.WalletRechargeInvoiceApplyDto;
import com.bsd.pjcloud.wallet.api.entity.recharge.WalletRechargeInvoiceEntity;
import com.bsd.pjcloud.wallet.api.vo.recharge.WalletRechargeInvoiceVo;
import com.bsd.pjcloud.wallet.service.WalletRechargeInvoiceService;
@@ -36,6 +40,25 @@ public class WalletRechargeInvoiceController {
private final WalletRechargeInvoiceService walletRechargeInvoiceService;
/* ************************************* start callback start ************************************* */
@Inner(value = false)
@PostMapping("/apply-callback")
public void applyCallback(@RequestBody ProcessNodeRecordAssignUserParamDto dto, @RequestParam(required = false) Long tenantId) {
walletRechargeInvoiceService.applyCallback(dto, tenantId);
}
/* ************************************* start callback start ************************************* */
@Operation(summary = "提交申请", description = "提交申请")
@SysLog("提交申请")
@PostMapping("/apply")
@Idempotent(expireTime = 3, info = "正在申请中,请勿重复操作")
public R apply(@Valid @RequestBody WalletRechargeInvoiceApplyDto body) {
walletRechargeInvoiceService.apply(body);
return R.ok(true);
}
@GetMapping("/get-invoice")
@Operation(summary = "批量充值/扣款发票信息")
public R<WalletRechargeInvoiceVo> getInvoice(@RequestParam Long id) {
@@ -4,7 +4,9 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.bsd.pjcloud.common.data.datascope.DataScope;
import com.bsd.pjcloud.common.security.service.PjcloudUser;
import com.bsd.pjcloud.flow.task.dto.ProcessNodeRecordAssignUserParamDto;
import com.bsd.pjcloud.wallet.api.dto.recharge.WalletRechargeBindInvoiceDto;
import com.bsd.pjcloud.wallet.api.dto.recharge.WalletRechargeInvoiceApplyDto;
import com.bsd.pjcloud.wallet.api.entity.recharge.WalletRechargeInvoiceEntity;
import com.bsd.pjcloud.wallet.api.vo.recharge.WalletRechargeInvoiceVo;
import jakarta.validation.Valid;
@@ -57,4 +59,19 @@ public interface WalletRechargeInvoiceService extends IService<WalletRechargeInv
* 批量删除发票
*/
void delByIds(ArrayList<Long> list);
/**
* 发票申请回调
*/
void applyCallback(ProcessNodeRecordAssignUserParamDto dto, Long tenantId);
/**
* 发票申请
*/
void apply(@Valid WalletRechargeInvoiceApplyDto body);
/**
* 盖章
*/
void stamp(WalletRechargeInvoiceEntity invoice);
}
@@ -1,20 +1,28 @@
package com.bsd.pjcloud.wallet.service.impl.recharge;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bsd.pjcloud.admin.api.dto.UserInfo;
import com.bsd.pjcloud.admin.api.entity.SysDept;
import com.bsd.pjcloud.admin.api.feign.RemoteDeptService;
import com.bsd.pjcloud.admin.api.feign.RemoteUserService;
import com.bsd.pjcloud.common.data.datascope.DataScope;
import com.bsd.pjcloud.common.data.tenant.TenantContextHolder;
import com.bsd.pjcloud.common.security.service.PjcloudUser;
import com.bsd.pjcloud.flow.task.constant.TaskCheckStatusEnum;
import com.bsd.pjcloud.flow.task.dto.ProcessNodeRecordAssignUserParamDto;
import com.bsd.pjcloud.wallet.api.constant.WalletBizRechargeEnum;
import com.bsd.pjcloud.wallet.api.constant.WalletRechargeInvoiceStatusEnum;
import com.bsd.pjcloud.wallet.api.dto.recharge.WalletRechargeBindInvoiceDto;
import com.bsd.pjcloud.wallet.api.dto.recharge.WalletRechargeInvoiceApplyDto;
import com.bsd.pjcloud.wallet.api.entity.recharge.WalletRechargeApplyEntity;
import com.bsd.pjcloud.wallet.api.entity.recharge.WalletRechargeImportEntity;
import com.bsd.pjcloud.wallet.api.entity.recharge.WalletRechargeInvoiceEntity;
@@ -27,7 +35,10 @@ import com.bsd.pjcloud.wallet.mapper.recharge.WalletRechargeImportMapper;
import com.bsd.pjcloud.wallet.mapper.recharge.WalletRechargeInvoiceMapper;
import com.bsd.pjcloud.wallet.service.WalletRechargeInvoiceService;
import com.bsd.pjcloud.wallet.utils.ConvertCnPriceUtil;
import com.bsd.pjcloud.wallet.utils.flow.FlowUtil;
import com.bsd.pjcloud.wallet.utils.flow.dto.WalletRechargeInvoiceFlowDto;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -40,14 +51,21 @@ import java.util.List;
/**
* 充值/扣款申请发票记录
*/
@Slf4j
@Service
@AllArgsConstructor
public class WalletRechargeInvoiceServiceImpl extends ServiceImpl<WalletRechargeInvoiceMapper, WalletRechargeInvoiceEntity> implements WalletRechargeInvoiceService {
static private final String TAG = "充值/扣款发票";
private final FlowUtil flowUtil;
private final WalletRechargeImportMapper importMapper;
private final WalletRechargeApplyMapper applyMapper;
private final RemoteUserService remoteUserService;
private final RemoteDeptService remoteDeptService;
private final RemoteWalletSettingService remoteWalletSettingService;
/**
@@ -239,6 +257,90 @@ public class WalletRechargeInvoiceServiceImpl extends ServiceImpl<WalletRecharge
return String.format("%07d", count);
}
/**
* 发票申请回调
*/
@Override
@Transactional(rollbackFor = Exception.class)
public void applyCallback(ProcessNodeRecordAssignUserParamDto dto, Long tenantId) {
if (!flowUtil.checkCallback(dto)) {
return;
}
if (ObjectUtil.isNotEmpty(tenantId) && ObjectUtil.notEqual(tenantId, 1L)) {
TenantContextHolder.setTenantId(tenantId);
}
String processId = dto.getProcessInstanceId();
WalletRechargeInvoiceEntity detail = baseMapper.selectOne(new LambdaQueryWrapper<WalletRechargeInvoiceEntity>().eq(WalletRechargeInvoiceEntity::getProcessId, processId));
if (ObjectUtil.isEmpty(detail)) {
return;
}
if (!ObjectUtil.equals(detail.getProcessStatus(), TaskCheckStatusEnum.PADDING.getCode())) {
log.error("|{}|重复的回调,dto:|{}|", TAG, JSON.toJSONString(dto));
return;
}
try {
Boolean isConsent = flowUtil.isConsent(dto);
String processStatus = isConsent ? TaskCheckStatusEnum.RESULT.getCode() : TaskCheckStatusEnum.REJECT.getCode();
baseMapper.updateById(WalletRechargeInvoiceEntity.builder().id(detail.getId()).processTime(LocalDateTime.now()).processStatus(processStatus).build());
if (isConsent) {
// 盖章
}
} catch (Exception e) {
e.printStackTrace();
log.error("|{}|审批回调意外的错误,dto:|{}|error:|{}|", TAG, JSON.toJSONString(dto), e.getMessage());
throw new RuntimeException(e);
}
}
/**
* 发票申请
*/
@Override
public void apply(WalletRechargeInvoiceApplyDto body) {
// 查询详情
WalletRechargeInvoiceEntity detail = baseMapper.selectById(body.getId());
if (ObjectUtil.isEmpty(detail)) {
throw new RuntimeException("发票申请不存在");
}
// 查询用户
UserInfo user = remoteUserService.getInnerByUserId(detail.getApplyUserId()).getData();
if (ObjectUtil.isEmpty(user)) {
throw new RuntimeException("申请人不存在");
}
// 查询部门
SysDept dept = remoteDeptService.getDeptByDeptId(detail.getApplyDeptId()).getData();
if (ObjectUtil.isEmpty(dept)) {
throw new RuntimeException("发起人部门不存在");
}
// 发起审批
WalletRechargeInvoiceFlowDto flowDto = new WalletRechargeInvoiceFlowDto();
flowDto.setApplyUsername(user.getSysUser().getUsername());
flowDto.setApplyUserId(user.getSysUser().getUserId());
flowDto.setApplyDeptName(dept.getName());
flowDto.setApplyDeptId(dept.getDeptId());
flowDto.setApplyCreateTime(LocalDateTimeUtil.format(detail.getCreateTime(), DatePattern.NORM_DATETIME_PATTERN));
flowDto.setRemark(detail.getRemark());
String processId = flowUtil.startFlow("TASK_RECHARGE_APPLY_FLOW", user.getSysUser(), detail.getId(), flowDto);
// 更新
WalletRechargeInvoiceEntity updateObj = new WalletRechargeInvoiceEntity();
updateObj.setId(detail.getId());
updateObj.setProcessId(processId);
updateObj.setApplyTime(LocalDateTime.now());
updateObj.setProcessStatus(TaskCheckStatusEnum.PADDING.getCode());
updateObj.setPicUrl(body.getPicUrl());
baseMapper.updateById(updateObj);
}
/**
* 盖章
*/
@Override
public void stamp(WalletRechargeInvoiceEntity invoice) {
}
/**
* 绑定发票
*/
@@ -0,0 +1,14 @@
package com.bsd.pjcloud.wallet.utils.flow.dto;
import com.bsd.pjcloud.flow.task.dto.base.FlowBaseDto;
import lombok.Data;
@Data
public class WalletRechargeInvoiceFlowDto extends FlowBaseDto {
/**
* 备注
*/
private String remark;
}