diff --git a/pjcloud-wallet/pjcloud-wallet-api/src/main/java/com/bsd/pjcloud/wallet/api/dto/recharge/WalletRechargeInvoiceApplyDto.java b/pjcloud-wallet/pjcloud-wallet-api/src/main/java/com/bsd/pjcloud/wallet/api/dto/recharge/WalletRechargeInvoiceApplyDto.java new file mode 100644 index 000000000..c6d339d9a --- /dev/null +++ b/pjcloud-wallet/pjcloud-wallet-api/src/main/java/com/bsd/pjcloud/wallet/api/dto/recharge/WalletRechargeInvoiceApplyDto.java @@ -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; + +} diff --git a/pjcloud-wallet/pjcloud-wallet-api/src/main/java/com/bsd/pjcloud/wallet/api/entity/recharge/WalletRechargeInvoiceEntity.java b/pjcloud-wallet/pjcloud-wallet-api/src/main/java/com/bsd/pjcloud/wallet/api/entity/recharge/WalletRechargeInvoiceEntity.java index 4d0fefd53..91809547e 100644 --- a/pjcloud-wallet/pjcloud-wallet-api/src/main/java/com/bsd/pjcloud/wallet/api/entity/recharge/WalletRechargeInvoiceEntity.java +++ b/pjcloud-wallet/pjcloud-wallet-api/src/main/java/com/bsd/pjcloud/wallet/api/entity/recharge/WalletRechargeInvoiceEntity.java @@ -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 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 excelVOList, BindingResult bindingResult) { return walletRechargeApplyService.readTopupExcel(excelVOList, bindingResult); } diff --git a/pjcloud-wallet/pjcloud-wallet-biz/src/main/java/com/bsd/pjcloud/wallet/controller/recharge/WalletRechargeInvoiceController.java b/pjcloud-wallet/pjcloud-wallet-biz/src/main/java/com/bsd/pjcloud/wallet/controller/recharge/WalletRechargeInvoiceController.java index 04adc6bf4..8ef2955ce 100644 --- a/pjcloud-wallet/pjcloud-wallet-biz/src/main/java/com/bsd/pjcloud/wallet/controller/recharge/WalletRechargeInvoiceController.java +++ b/pjcloud-wallet/pjcloud-wallet-biz/src/main/java/com/bsd/pjcloud/wallet/controller/recharge/WalletRechargeInvoiceController.java @@ -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 getInvoice(@RequestParam Long id) { diff --git a/pjcloud-wallet/pjcloud-wallet-biz/src/main/java/com/bsd/pjcloud/wallet/service/WalletRechargeInvoiceService.java b/pjcloud-wallet/pjcloud-wallet-biz/src/main/java/com/bsd/pjcloud/wallet/service/WalletRechargeInvoiceService.java index 4073883ad..0868143e2 100644 --- a/pjcloud-wallet/pjcloud-wallet-biz/src/main/java/com/bsd/pjcloud/wallet/service/WalletRechargeInvoiceService.java +++ b/pjcloud-wallet/pjcloud-wallet-biz/src/main/java/com/bsd/pjcloud/wallet/service/WalletRechargeInvoiceService.java @@ -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 list); + + /** + * 发票申请回调 + */ + void applyCallback(ProcessNodeRecordAssignUserParamDto dto, Long tenantId); + + /** + * 发票申请 + */ + void apply(@Valid WalletRechargeInvoiceApplyDto body); + + /** + * 盖章 + */ + void stamp(WalletRechargeInvoiceEntity invoice); } \ No newline at end of file diff --git a/pjcloud-wallet/pjcloud-wallet-biz/src/main/java/com/bsd/pjcloud/wallet/service/impl/recharge/WalletRechargeInvoiceServiceImpl.java b/pjcloud-wallet/pjcloud-wallet-biz/src/main/java/com/bsd/pjcloud/wallet/service/impl/recharge/WalletRechargeInvoiceServiceImpl.java index 2c8b711ba..79e2b6667 100644 --- a/pjcloud-wallet/pjcloud-wallet-biz/src/main/java/com/bsd/pjcloud/wallet/service/impl/recharge/WalletRechargeInvoiceServiceImpl.java +++ b/pjcloud-wallet/pjcloud-wallet-biz/src/main/java/com/bsd/pjcloud/wallet/service/impl/recharge/WalletRechargeInvoiceServiceImpl.java @@ -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 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().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) { + + } + /** * 绑定发票 */ diff --git a/pjcloud-wallet/pjcloud-wallet-biz/src/main/java/com/bsd/pjcloud/wallet/utils/flow/dto/WalletRechargeInvoiceFlowDto.java b/pjcloud-wallet/pjcloud-wallet-biz/src/main/java/com/bsd/pjcloud/wallet/utils/flow/dto/WalletRechargeInvoiceFlowDto.java new file mode 100644 index 000000000..0b338c53f --- /dev/null +++ b/pjcloud-wallet/pjcloud-wallet-biz/src/main/java/com/bsd/pjcloud/wallet/utils/flow/dto/WalletRechargeInvoiceFlowDto.java @@ -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; + +}