feat:发票流程

This commit is contained in:
dzc committed 2025-06-25 20:45:31 +08:00
1 parent 6ac12d8d44
commit 5cc25a197b
9 files changed
+134 -16

No files matched your search

@@ -13,9 +13,11 @@ import java.util.Arrays;
@AllArgsConstructor
public enum WalletRechargeInvoiceStatusEnum {
UNCHECKED("1", "未审核"),
CHECKED("2", "审核通过"),
CANCELLATION("3", "作废"),
UNBIND("1", "未绑定充值"),
BINDED("2", "已绑定充值"),
UNCHECKED("3", "未审核"),
CHECKED("4", "审核成功"),
CANCELLATION("5", "作废"),
;
private final String code;
@@ -27,4 +29,10 @@ public enum WalletRechargeInvoiceStatusEnum {
.findFirst().get();
}
public static WalletRechargeInvoiceStatusEnum codeOf(String code) {
return Arrays.stream(WalletRechargeInvoiceStatusEnum.values())
.filter(v -> ObjectUtil.equal(v.getCode(), code))
.findFirst().get();
}
}
@@ -0,0 +1,18 @@
package com.bsd.pjcloud.wallet.api.dto.recharge;
import lombok.Data;
@Data
public class WalletRechargeSaveTopupDto {
/**
* 充值类型
*/
private String bizType;
/**
* 发票id
*/
private Long invoiceId;
}
@@ -12,6 +12,7 @@ import com.bsd.pjcloud.common.security.annotation.Inner;
import com.bsd.pjcloud.flow.task.dto.ProcessNodeRecordAssignUserParamDto;
import com.bsd.pjcloud.wallet.api.dto.recharge.WalletRechargeApplyDto;
import com.bsd.pjcloud.wallet.api.dto.recharge.WalletRechargeImportDto;
import com.bsd.pjcloud.wallet.api.dto.recharge.WalletRechargeSaveTopupDto;
import com.bsd.pjcloud.wallet.api.dto.recharge.excel.WalletRechargeExcelDto;
import com.bsd.pjcloud.wallet.api.entity.recharge.WalletRechargeApplyEntity;
import com.bsd.pjcloud.wallet.api.vo.recharge.excel.WalletRechargeByApplyExcelVo;
@@ -48,6 +49,13 @@ public class WalletRechargeApplyController {
}
/* ************************************* start callback start ************************************* */
@PostMapping("/save-topup")
@Operation(summary = "新增充值")
public R comparePageJoin(@RequestBody WalletRechargeSaveTopupDto dto) {
walletRechargeApplyService.saveTopup(dto);
return R.ok();
}
@GetMapping("/compare-page-join")
@Operation(summary = "批量充值/扣款记录")
public R comparePageJoin(@ParameterObject Page page, @ParameterObject WalletRechargeApplyDto dto) {
@@ -140,8 +148,8 @@ public class WalletRechargeApplyController {
}
@PostMapping("/read-excel")
public R readExcel(@RequestExcel List<WalletRechargeExcelDto> excelVOList, BindingResult bindingResult) {
return walletRechargeApplyService.readExcel(excelVOList, bindingResult);
public R readExcel(@RequestExcel List<WalletRechargeExcelDto> excelVOList, BindingResult bindingResult, @RequestParam(required = false) String bizType) {
return walletRechargeApplyService.readExcel(excelVOList, bindingResult, bizType);
}
@PostMapping("/read-topup-excel")
@@ -71,8 +71,9 @@ public interface WalletRechargeApplyMapper extends PjcloudBaseMapper<WalletRecha
wrapper.orderByDesc(WalletRechargeApplyEntity::getProcessTime)
.orderByDesc(WalletRechargeApplyEntity::getId);
} else {
wrapper.orderByDesc(WalletRechargeApplyEntity::getCreateTime)
.orderByDesc(WalletRechargeApplyEntity::getId);
// wrapper.orderByDesc(WalletRechargeApplyEntity::getApplyTime)
// .orderByDesc(WalletRechargeApplyEntity::getCreateTime);
wrapper.orderByDesc(WalletRechargeApplyEntity::getCreateTime);
}
Page list = selectPageByScope(page, wrapper, DataScope.of());
@@ -2,6 +2,7 @@ package com.bsd.pjcloud.wallet.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bsd.pjcloud.wallet.api.dto.recharge.WalletRechargeApplyDto;
import com.bsd.pjcloud.wallet.api.dto.recharge.WalletRechargeSaveTopupDto;
import com.bsd.pjcloud.wallet.api.vo.recharge.WalletRechargeApplyCompareAceVo;
public interface WalletRechargeApplyComposeService {
@@ -6,6 +6,7 @@ import com.bsd.pjcloud.common.core.util.R;
import com.bsd.pjcloud.flow.task.dto.ProcessNodeRecordAssignUserParamDto;
import com.bsd.pjcloud.wallet.api.dto.recharge.WalletRechargeApplyDto;
import com.bsd.pjcloud.wallet.api.dto.recharge.WalletRechargeImportDto;
import com.bsd.pjcloud.wallet.api.dto.recharge.WalletRechargeSaveTopupDto;
import com.bsd.pjcloud.wallet.api.dto.recharge.excel.WalletRechargeExcelDto;
import com.bsd.pjcloud.wallet.api.entity.recharge.WalletRechargeApplyEntity;
import com.bsd.pjcloud.wallet.api.vo.recharge.WalletRechargeApplyVo;
@@ -17,6 +18,11 @@ import java.util.List;
public interface WalletRechargeApplyService extends IService<WalletRechargeApplyEntity> {
/**
* 新增充值
*/
void saveTopup(WalletRechargeSaveTopupDto dto);
void create(WalletRechargeApplyEntity dto);
Boolean edit(WalletRechargeApplyDto dto);
@@ -43,7 +49,7 @@ public interface WalletRechargeApplyService extends IService<WalletRechargeApply
/**
* 读取记账扣款、退回各自食堂excel内容
*/
R readExcel(List<WalletRechargeExcelDto> excelVOList, BindingResult bindingResult);
R readExcel(List<WalletRechargeExcelDto> excelVOList, BindingResult bindingResult, String bizType);
/**
* 读取充值excel内容
@@ -33,11 +33,13 @@ import com.bsd.pjcloud.flow.task.dto.TaskDto;
import com.bsd.pjcloud.flow.task.dto.TaskParamDto;
import com.bsd.pjcloud.wallet.api.constant.WalletBizEnum;
import com.bsd.pjcloud.wallet.api.constant.WalletBizRechargeEnum;
import com.bsd.pjcloud.wallet.api.constant.WalletRechargeInvoiceStatusEnum;
import com.bsd.pjcloud.wallet.api.constant.WalletTypeEnum;
import com.bsd.pjcloud.wallet.api.dto.WalletManageDto;
import com.bsd.pjcloud.wallet.api.dto.WalletTypeDto;
import com.bsd.pjcloud.wallet.api.dto.recharge.WalletRechargeApplyDto;
import com.bsd.pjcloud.wallet.api.dto.recharge.WalletRechargeImportDto;
import com.bsd.pjcloud.wallet.api.dto.recharge.WalletRechargeSaveTopupDto;
import com.bsd.pjcloud.wallet.api.dto.recharge.excel.WalletRechargeExcelDto;
import com.bsd.pjcloud.wallet.api.entity.WalletManageEntity;
import com.bsd.pjcloud.wallet.api.entity.WalletTypeEntity;
@@ -62,6 +64,7 @@ import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.BindingResult;
@@ -103,6 +106,46 @@ public class WalletRechargeApplyServiceImpl extends ServiceImpl<WalletRechargeAp
private final FlowUtil flowUtil;
/**
* 新增充值
*/
@Override
@Transactional(rollbackFor = Exception.class)
public void saveTopup(WalletRechargeSaveTopupDto dto) {
// 查询一下发票记录
WalletRechargeInvoiceEntity invoice = walletRechargeInvoiceService.getById(dto.getInvoiceId());
if (ObjectUtil.isEmpty(invoice)) throw new RuntimeException("发票记录不存在");
if (ObjectUtil.isNotEmpty(invoice.getApplyId())) throw new RuntimeException("该发票已被绑定");
WalletRechargeApplyEntity apply = new WalletRechargeApplyEntity();
apply.setInvoiceId(invoice.getId());
apply.setUserId(invoice.getApplyUserId());
apply.setBizType(dto.getBizType());
apply.setWalletTypeId(null);
apply.setDeptId(invoice.getApplyDeptId());
apply.setImportTime(invoice.getCreateTime().toLocalDate());
apply.setRemark(invoice.getRemark());
baseMapper.insert(apply);
// 更新import记录表的applyId
List<WalletRechargeImportEntity> list = rechargeImportService.list(new LambdaQueryWrapper<WalletRechargeImportEntity>().eq(WalletRechargeImportEntity::getInvoiceId, invoice.getId()).isNull(WalletRechargeImportEntity::getApplyId));
if (ObjectUtil.isNotEmpty(list)) {
List<WalletRechargeImportEntity> updateObjList = list.stream().map(v -> {
WalletRechargeImportEntity item = new WalletRechargeImportEntity();
item.setId(v.getId());
item.setApplyId(apply.getId());
return item;
}).toList();
rechargeImportService.updateBatchById(updateObjList);
}
// 更新发票状态
WalletRechargeInvoiceEntity updateObj = new WalletRechargeInvoiceEntity();
updateObj.setId(invoice.getId());
updateObj.setStatus(WalletRechargeInvoiceStatusEnum.BINDED.getCode());
updateObj.setApplyId(apply.getId());
walletRechargeInvoiceService.updateById(updateObj);
}
@Override
public void create(WalletRechargeApplyEntity dto) {
PjcloudUser loginUser = SecurityUtils.getUser();
@@ -149,6 +192,10 @@ public class WalletRechargeApplyServiceImpl extends ServiceImpl<WalletRechargeAp
dto.setProcessInstanceIdList(List.of(detail.getProcessId()));
flowEngineService.stopProcessInstance(dto).getData();
}
// 如果有发票要删除一下
if (ObjectUtil.isNotEmpty(detail.getInvoiceId())) {
walletRechargeInvoiceService.removeById(detail.getInvoiceId());
}
// 删除申请记录
baseMapper.deleteById(v);
// 删除申请记录条目
@@ -238,6 +285,13 @@ public class WalletRechargeApplyServiceImpl extends ServiceImpl<WalletRechargeAp
updateObj.setProcessStatus(TaskCheckStatusEnum.PADDING.getCode());
updateObj.setApplyTime(LocalDateTime.now());
baseMapper.updateById(updateObj);
// 如果有绑定的发票
if (ObjectUtil.isNotEmpty(detail.getInvoiceId())) {
WalletRechargeInvoiceEntity invoiceUpdate = new WalletRechargeInvoiceEntity();
invoiceUpdate.setId(detail.getInvoiceId());
invoiceUpdate.setStatus(WalletRechargeInvoiceStatusEnum.UNCHECKED.getCode());
walletRechargeInvoiceService.updateById(invoiceUpdate);
}
// 更新之前的总金额
getSelf().updateBeforePrice(detail);
}
@@ -254,7 +308,7 @@ public class WalletRechargeApplyServiceImpl extends ServiceImpl<WalletRechargeAp
@Override
@Transactional(rollbackFor = Exception.class)
public R readExcel(List<WalletRechargeExcelDto> excelVOList, BindingResult bindingResult) {
public R readExcel(List<WalletRechargeExcelDto> excelVOList, BindingResult bindingResult, String bizType) {
ImmutablePair<List<ErrorMessage>, List<WalletRechargeExcelDto>> pair = validateExcelData(excelVOList, bindingResult);
List<ErrorMessage> errorMessages = pair.getLeft();
List<WalletRechargeExcelDto> list = pair.getRight();
@@ -263,6 +317,7 @@ public class WalletRechargeApplyServiceImpl extends ServiceImpl<WalletRechargeAp
WalletRechargeApplyEntity insertObj = new WalletRechargeApplyEntity();
insertObj.setDeptId(loginUser.getDeptId());
insertObj.setUserId(loginUser.getId());
insertObj.setBizType(bizType);
int i = baseMapper.insert(insertObj);
if (i <= 0) {
throw new RuntimeException("导入失败");
@@ -382,6 +437,15 @@ public class WalletRechargeApplyServiceImpl extends ServiceImpl<WalletRechargeAp
Boolean isConsent = flowUtil.isConsent(dto);
String processStatus = isConsent ? TaskCheckStatusEnum.RESULT.getCode() : TaskCheckStatusEnum.REJECT.getCode();
baseMapper.updateById(WalletRechargeApplyEntity.builder().id(detail.getId()).processTime(LocalDateTime.now()).processStatus(processStatus).build());
// 如果有绑定的发票
if (ObjectUtil.isNotEmpty(detail.getInvoiceId())) {
WalletRechargeInvoiceEntity invoiceUpdate = new WalletRechargeInvoiceEntity();
invoiceUpdate.setId(detail.getInvoiceId());
invoiceUpdate.setStatus(WalletRechargeInvoiceStatusEnum.CHECKED.getCode());
walletRechargeInvoiceService.updateById(invoiceUpdate);
}
if (isConsent) {
List<WalletRechargeImportEntity> importList = rechargeImportService.list(new LambdaQueryWrapper<WalletRechargeImportEntity>().eq(WalletRechargeImportEntity::getApplyId, detail.getId()));
if (ObjectUtil.isEmpty(importList)) {
@@ -67,6 +67,11 @@ public class WalletRechargeInvoiceServiceImpl extends ServiceImpl<WalletRecharge
// 转换为元
Double price = BigDecimal.valueOf(detail.getTotalPrice()).divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP).doubleValue();
detail.setTotalPriceCnStr(ConvertCnPriceUtil.convert(String.valueOf(price)));
// 生成款项
WalletRechargeInvoiceItemVo item = new WalletRechargeInvoiceItemVo();
item.setName("伙食费充值");
item.setPrice(price);
detail.setItemJson(JSONUtil.toJsonStr(List.of(item)));
return detail;
}
@@ -94,7 +99,7 @@ public class WalletRechargeInvoiceServiceImpl extends ServiceImpl<WalletRecharge
WalletRechargeInvoiceVo result = new WalletRechargeInvoiceVo();
WalletRechargeInvoiceEntity InvoiceEntity = baseMapper.selectOne(new LambdaQueryWrapper<WalletRechargeInvoiceEntity>()
.eq(WalletRechargeInvoiceEntity::getApplyId, id)
.eq(WalletRechargeInvoiceEntity::getStatus, WalletRechargeInvoiceStatusEnum.UNCHECKED.getCode())
.eq(WalletRechargeInvoiceEntity::getStatus, WalletRechargeInvoiceStatusEnum.UNBIND.getCode())
);
if (ObjectUtil.isNotEmpty(InvoiceEntity)) {
result = BeanUtil.copyProperties(InvoiceEntity, WalletRechargeInvoiceVo.class);
@@ -136,7 +141,7 @@ public class WalletRechargeInvoiceServiceImpl extends ServiceImpl<WalletRecharge
result.setTotalPriceCnStr(ConvertCnPriceUtil.convert(String.valueOf(price)));
result.setPayeeDept(walletSetting.getTopupDeptStr());
result.setPayeeUser(payeeUser);
result.setStatus(WalletRechargeInvoiceStatusEnum.UNCHECKED.getCode());
result.setStatus(WalletRechargeInvoiceStatusEnum.UNBIND.getCode());
result.setItemJson(JSONUtil.toJsonStr(List.of(item)));
result.setRemark("");
return result;
@@ -172,7 +177,7 @@ public class WalletRechargeInvoiceServiceImpl extends ServiceImpl<WalletRecharge
saveObj.setPayeeDept(walletSetting.getTopupDeptStr());
}
}
saveObj.setStatus(WalletRechargeInvoiceStatusEnum.UNCHECKED.getCode());
saveObj.setStatus(WalletRechargeInvoiceStatusEnum.UNBIND.getCode());
baseMapper.insert(saveObj);
return saveObj;
}
@@ -181,15 +186,20 @@ public class WalletRechargeInvoiceServiceImpl extends ServiceImpl<WalletRecharge
* 批量删除发票
*/
@Override
@Transactional(rollbackFor = Exception.class)
public void delByIds(ArrayList<Long> list) {
if (ObjectUtil.isEmpty(list)) return;
for (Long v : list) {
WalletRechargeInvoiceEntity detail = baseMapper.selectById(v);
if (ObjectUtil.isEmpty(detail)) continue;
if (ObjectUtil.isNotEmpty(detail.getStatus()) && ObjectUtil.notEqual(detail.getStatus(), WalletRechargeInvoiceStatusEnum.UNCHECKED.getCode())) {
UserInfo userInfo = remoteUserService.getByUserId(detail.getApplyId()).getData();
throw new RuntimeException("用户<" + userInfo.getSysUser().getName() + ">发起的审批不能删除");
if (ObjectUtil.isEmpty(detail) || ObjectUtil.isEmpty(detail.getApplyId())) continue;
if (ObjectUtil.isNotEmpty(detail.getStatus()) && ObjectUtil.notEqual(detail.getStatus(), WalletRechargeInvoiceStatusEnum.UNBIND.getCode())) {
UserInfo userInfo = remoteUserService.getByUserId(detail.getApplyUserId()).getData();
throw new RuntimeException("用户<" + userInfo.getSysUser().getName() + ">创建的发票已经" + WalletRechargeInvoiceStatusEnum.codeOf(detail.getStatus()).getDesc() + "不能删除");
}
// 删除申请记录
baseMapper.deleteById(v);
// 删除申请记录条目
importMapper.delete(new LambdaQueryWrapper<WalletRechargeImportEntity>().eq(WalletRechargeImportEntity::getApplyId, v));
}
}
@@ -210,6 +220,7 @@ public class WalletRechargeInvoiceServiceImpl extends ServiceImpl<WalletRecharge
@Transactional(rollbackFor = Exception.class)
public void bindInvoice(WalletRechargeBindInvoiceDto dto) {
WalletRechargeInvoiceEntity entity = BeanUtil.toBean(dto, WalletRechargeInvoiceVo.class);
entity.setApplyId(null);
baseMapper.insertOrUpdate(entity);
LambdaUpdateWrapper<WalletRechargeApplyEntity> updateWrapper = new LambdaUpdateWrapper<WalletRechargeApplyEntity>()
.set(WalletRechargeApplyEntity::getInvoiceId, entity.getId())
@@ -26,6 +26,7 @@
</sql>
<sql id="whereA">
a.del_flag = '0'
<if test="dto.status != null">
and a.status = #{dto.status}
</if>