开票=》根据充值金额开票

This commit is contained in:
qjq
2024-11-21 15:53:02 +08:00
parent c48f1a9fb6
commit b43dafe056
4 changed files with 84 additions and 10 deletions

View File

@ -35,13 +35,13 @@ public class AppBillingController {
@PostMapping("/create")
@Operation(summary = "创建开票记录")
public CommonResult<String> createBilling(@Valid @RequestBody BillingSaveReqVO createReqVO) {
return success(billingService.createBilling(createReqVO));
return success(billingService.createBillingUnit(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新开票记录")
public CommonResult<Boolean> updateBilling(@Valid @RequestBody BillingSaveReqVO updateReqVO) {
billingService.updateBilling(updateReqVO);
billingService.updateBillingUnit(updateReqVO);
return success(true);
}
@ -62,8 +62,8 @@ public class AppBillingController {
}
@GetMapping("/moeny")
@Operation(summary = "获得开票金额与未开票金额")
public CommonResult<BillingRespMoneyVO> getBillingPage(@RequestParam("userId")Long userId,@RequestParam("carteenId") Long carteenId) {
return success(billingService.getHaveWithoutMoney(userId,carteenId));
public CommonResult<BillingRespMoneyVO> getBillingPage(@RequestParam("userId")Long userId,@RequestParam(value = "carteenId",required = false) Long carteenId) {
return success(billingService.getUserHaveWithoutMoney(userId,carteenId));
}
@GetMapping("/page")
@Operation(summary = "获得开票记录分页")
@ -77,7 +77,7 @@ public class AppBillingController {
@GetMapping("/totalMoney")
@Operation(summary = "获取月时间段的金额")
public CommonResult<BigDecimal> getBillingPage(BillingPageDataVo vo) {
BigDecimal totalMoney = billingService.getTotalMoney(vo);
BigDecimal totalMoney = billingService.getUserTotalMoney(vo);
return success(totalMoney);
}
@GetMapping("/data")
@ -88,7 +88,7 @@ public class AppBillingController {
}
@GetMapping("/TypeTotal")
@Operation(summary = "获取开票订单数量")
public CommonResult<Map<Integer, Integer>> getBillingTypeTotal(@RequestParam("carteenId") Long carteenId,@RequestParam("userId") Long userId) {
public CommonResult<Map<Integer, Integer>> getBillingTypeTotal(@RequestParam(value = "carteenId",required = false) Long carteenId,@RequestParam("userId") Long userId) {
Map<Integer, Integer> billingTypeTotal = billingService.getBillingTypeTotal(carteenId, userId);
return success(billingTypeTotal);
}

View File

@ -13,7 +13,8 @@ public enum BillingEnum {
//0食堂发票,1超市发票,2太空舱;
BILLING_CANTEEN(0,"食堂"),
BILLING_SUPERMARKET(1,"超市"),
BILLING_SPACE_CAPSULE(2,"太空舱");
BILLING_SPACE_CAPSULE(2,"太空舱"),
BILLING_SPACE_DANWEI(3,"单位");
/**
* 编码
*/

View File

@ -39,6 +39,7 @@ public interface BillingService {
* @param updateReqVO 更新信息
*/
void updateBilling(@Valid BillingSaveReqVO updateReqVO);
void updateBillingUnit(@Valid BillingSaveReqVO updateReqVO);
/**
* 删除开票记录
@ -63,6 +64,7 @@ public interface BillingService {
*/
PageResult<BillingDO> getBillingPage(BillingPageReqVO pageReqVO);
BillingRespMoneyVO getHaveWithoutMoney(Long userId,Long carteenId);
BillingRespMoneyVO getUserHaveWithoutMoney(Long userId,Long carteenId);
BillingRespMoneyVO getHaveWithoutMoney(Long userId);
/**
@ -70,6 +72,7 @@ public interface BillingService {
* @return
*/
BigDecimal getTotalMoney(BillingPageDataVo vo);
BigDecimal getUserTotalMoney(BillingPageDataVo vo);
Object getData(BillingPageDataVo vo);
String getMemberId(Long userId);

View File

@ -38,6 +38,7 @@ import cn.iocoder.yudao.module.member.enums.*;
import cn.iocoder.yudao.module.member.service.orderdetail.OrderDetailService;
import cn.iocoder.yudao.module.member.service.storeorderdetail.StoreOrderDetailService;
import cn.iocoder.yudao.module.system.api.carteen.CarteenApi;
import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.transaction.annotation.Transactional;
@ -233,14 +234,17 @@ public class BillingServiceImpl implements BillingService {
@Override
@Transactional(rollbackFor = Exception.class)
public String createBillingUnit(BillingSaveReqVO createReqVO) {
Long loginUserId = SecurityFrameworkUtils.getLoginUserId();
// 插入 BillingDO 对象并生成唯一主键
BillingDO billing = BeanUtils.toBean(createReqVO, BillingDO.class);
Set<Long> orderId = createReqVO.getOrderId();
if(orderId==null){
createReqVO.setOrderId(new HashSet<>(getMemberListByUserId(billing.getUserId()))) ;
}
MemberGroupDO memberGroupDO = memberGroupDO(billing.getUserId());
billing.setId(IdUtil.getSnowflakeNextId() + "");
billing.setUserName(memberGroupDO.getName());
billing.setUserPhone(String.valueOf(memberGroupDO.getId()));
billing.setUserId(loginUserId);
billing.setUserId(billing.getUserId());
//查询单位充值的金额
List<CardDO> moneyByUserIds = cardMapper.getMoneyByUserIds(createReqVO.getOrderId(), CardDO.ADD, CostTypeEnum.ADMIN_PAY.getCode(),BillingStatusEnum.BILLING_INVOICING_REJECTION.getCode());
if(CollUtil.isEmpty(moneyByUserIds))throw exception(BILLING_NOT_ORDER_EXISTS);
@ -252,6 +256,7 @@ public class BillingServiceImpl implements BillingService {
f.setBillingExist(BillingStatusEnum.BILLING_INVOICING.getCode());
f.setBillingNum(billing.getId());
});
billing.setBillingType(BillingEnum.BILLING_SPACE_DANWEI.getCode());
cardMapper.updateBatch(moneyByUserIds);
billing.setBillingMoney(totalMoney);
billing.setOrderId(JSONUtil.toJsonStr(createReqVO.getOrderId()));
@ -356,7 +361,48 @@ public class BillingServiceImpl implements BillingService {
}
billingMapper.updateById(updateObj);
}
public void updateBillingUnit(BillingSaveReqVO updateReqVO) {
// 校验存在
BillingDO billingDO = billingMapper.selectById(updateReqVO.getId());
if (billingDO== null) {
throw exception(BILLING_NOT_EXISTS);
}
// 更新
BillingDO updateObj = BeanUtils.toBean(updateReqVO, BillingDO.class);
updateObj.setOrderId(billingDO.getOrderId());
String orderId = updateObj.getOrderId();
JSONArray jsonArray = JSONUtil.parseArray(orderId);
// 转换为 Set<Long>
Set<Long> orderIds = jsonArray.stream()
.map(object -> Long.parseLong(object.toString())) // 将每个元素转换为 Long
.collect(Collectors.toSet());
//开票成功是根据pdf上传成功没
if(StrUtil.isNotBlank(updateObj.getPdfUrl())){
//上传成功 修改状态
updateObj.setStatus(BillingStatusEnum.BILLING_INVOICING_IS_COMPLETE.getCode());
//设置同意人
updateObj.setSystemId(SecurityFrameworkUtils.getLoginUserId());
//拒绝就把锁住的订单释放掉
LambdaUpdateChainWrapper<CardDO> wrapper = new LambdaUpdateChainWrapper<>(cardMapper);
wrapper.in(CardDO::getId,orderIds);
wrapper.set(CardDO::getBillingExist,BillingStatusEnum.BILLING_INVOICING_IS_COMPLETE.getCode());
cardMapper.update(wrapper);
}else{
//开票回拒
if(StrUtil.isBlank(updateObj.getRefuseDetails())){
throw exception(BILLING_NOT_ORDER_REFUSE);
}
updateObj.setStatus(BillingStatusEnum.BILLING_INVOICING_REJECTION.getCode());
updateObj.setRefuseTime(LocalDateTime.now());
//拒绝就把锁住的订单释放掉
LambdaUpdateChainWrapper<CardDO> wrapper = new LambdaUpdateChainWrapper<>(cardMapper);
wrapper.in(CardDO::getId,orderIds);
wrapper.set(CardDO::getBillingExist,BillingStatusEnum.BILLING_INVOICING_REJECTION.getCode());
wrapper.set(CardDO::getBillingNum,null);
cardMapper.update(wrapper);
}
billingMapper.updateById(updateObj);
}
@Override
public void deleteBilling(String id) {
// 校验存在
@ -394,6 +440,19 @@ public class BillingServiceImpl implements BillingService {
return response;
}
@Override
public BillingRespMoneyVO getUserHaveWithoutMoney(Long userId, Long carteenId) {
List<Long> memberList = getMemberListByUserId(userId);
// 创建 BillingRespMoneyVO 对象
BillingRespMoneyVO response = new BillingRespMoneyVO();
// 查询已开票的金额
BigDecimal haveMoney = getTotalMoneyForBilling(userId, BillingStatusEnum.BILLING_INVOICING_IS_COMPLETE.getCode());
response.setHaveMoney(haveMoney);
BigDecimal moneyByUserIds = cardMapper.getTotalMoneyByuserIds(memberList, CardDO.ADD, CostTypeEnum.ADMIN_PAY.getCode());
response.setWithoutMoney(moneyByUserIds);
return response;
}
@Override
public BillingRespMoneyVO getHaveWithoutMoney(Long userId) {
List<Long> memberList = getMemberListByUserId(userId);
@ -509,6 +568,17 @@ public class BillingServiceImpl implements BillingService {
return calculateTotalMoneyByBillingType(vo.getBillingType(), data);
}
@Override
public BigDecimal getUserTotalMoney(BillingPageDataVo vo) {
// 获取当前单位下的所有成员
List<Long> ids = getMemberListByUserId(vo.getUserId());
List<CardDO> moneyByUserIds = cardMapper.getMoneyByUserIds(ids, CardDO.ADD, CostTypeEnum.ADMIN_PAY.getCode(), BillingStatusEnum.BILLING_INVOICING_REJECTION.getCode());
return moneyByUserIds.stream()
.map(CardDO::getChangeMoney)
.filter(Objects::nonNull)
.reduce(BigDecimal.ZERO, BigDecimal::add);
}
@Override
public Object getData(BillingPageDataVo vo) {
// 获取当前单位下的所有成员