- 新增其他收支实体类WmsOtherIncome及其相关VO、BO类 - 实现其他收支的增删改查接口IWmsOtherIncomeService - 添加其他收支控制器WmsOtherIncomeController支持RESTful请求 - 配置MyBatis映射文件及Mapper接口支持数据库操作 - 在应付和应收业务中增加时间范围筛选字段和逻辑
187 lines
7.1 KiB
Java
187 lines
7.1 KiB
Java
package com.klp.service.impl;
|
||
|
||
import cn.hutool.core.bean.BeanUtil;
|
||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||
import com.klp.common.core.page.TableDataInfo;
|
||
import com.klp.common.core.domain.PageQuery;
|
||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||
import com.klp.common.utils.StringUtils;
|
||
import com.klp.domain.WmsJournal;
|
||
import com.klp.mapper.WmsCustomerMapper;
|
||
import com.klp.mapper.WmsJournalMapper;
|
||
import com.klp.service.IWmsJournalService;
|
||
import lombok.RequiredArgsConstructor;
|
||
import org.springframework.stereotype.Service;
|
||
import com.klp.domain.bo.WmsReceivableBo;
|
||
import com.klp.domain.vo.WmsReceivableVo;
|
||
import com.klp.domain.WmsReceivable;
|
||
import com.klp.mapper.WmsReceivableMapper;
|
||
import com.klp.service.IWmsReceivableService;
|
||
import org.springframework.transaction.annotation.Transactional;
|
||
|
||
import javax.annotation.Resource;
|
||
import java.math.BigDecimal;
|
||
import java.util.Date;
|
||
import java.util.List;
|
||
import java.util.Map;
|
||
import java.util.Collection;
|
||
|
||
/**
|
||
* 应收款管理(宽松版)Service业务层处理
|
||
*
|
||
* @author klp
|
||
* @date 2025-08-13
|
||
*/
|
||
@RequiredArgsConstructor
|
||
@Service
|
||
public class WmsReceivableServiceImpl implements IWmsReceivableService {
|
||
|
||
private final WmsReceivableMapper baseMapper;
|
||
|
||
@Resource
|
||
private WmsJournalMapper journalMapper;
|
||
@Resource
|
||
private WmsCustomerMapper customerMapper;
|
||
@Resource
|
||
private IWmsJournalService wmsJournalService;
|
||
|
||
/**
|
||
* 查询应收款管理(宽松版)
|
||
*/
|
||
@Override
|
||
public WmsReceivableVo queryById(Long receivableId){
|
||
return baseMapper.selectVoById(receivableId);
|
||
}
|
||
|
||
/**
|
||
* 查询应收款管理(宽松版)列表
|
||
*/
|
||
@Override
|
||
public TableDataInfo<WmsReceivableVo> queryPageList(WmsReceivableBo bo, PageQuery pageQuery) {
|
||
QueryWrapper<WmsReceivable> lqw = buildQueryWrapperPlus(bo);
|
||
Page<WmsReceivableVo> result = baseMapper.selectVoPagePlus(pageQuery.build(), lqw);
|
||
return TableDataInfo.build(result);
|
||
}
|
||
|
||
private QueryWrapper<WmsReceivable> buildQueryWrapperPlus(WmsReceivableBo bo) {
|
||
QueryWrapper<WmsReceivable> lqw = Wrappers.query();
|
||
lqw.eq("r.del_flag", 0);
|
||
lqw.eq(bo.getCustomerId() != null, "r.customer_id", bo.getCustomerId());
|
||
lqw.eq(bo.getOrderId() != null, "r.order_id", bo.getOrderId());
|
||
lqw.eq(bo.getDueDate() != null, "r.due_date", bo.getDueDate());
|
||
lqw.eq(bo.getAmount() != null, "r.amount", bo.getAmount());
|
||
lqw.eq(bo.getPaidAmount() != null, "r.paid_amount", bo.getPaidAmount());
|
||
lqw.eq(bo.getBalanceAmount() != null, "r.balance_amount", bo.getBalanceAmount());
|
||
lqw.eq(StringUtils.isNotBlank(bo.getStatus()), "r.status", bo.getStatus());
|
||
//根据创建时间查询范围Date startTime Date endTime
|
||
if (bo.getStartTime() != null && bo.getEndTime() != null) {
|
||
lqw.between("r.create_time", bo.getStartTime(), bo.getEndTime());
|
||
}
|
||
return lqw;
|
||
}
|
||
|
||
/**
|
||
* 查询应收款管理(宽松版)列表
|
||
*/
|
||
@Override
|
||
public List<WmsReceivableVo> queryList(WmsReceivableBo bo) {
|
||
LambdaQueryWrapper<WmsReceivable> lqw = buildQueryWrapper(bo);
|
||
return baseMapper.selectVoList(lqw);
|
||
}
|
||
|
||
private LambdaQueryWrapper<WmsReceivable> buildQueryWrapper(WmsReceivableBo bo) {
|
||
Map<String, Object> params = bo.getParams();
|
||
LambdaQueryWrapper<WmsReceivable> lqw = Wrappers.lambdaQuery();
|
||
lqw.eq(bo.getCustomerId() != null, WmsReceivable::getCustomerId, bo.getCustomerId());
|
||
lqw.eq(bo.getOrderId() != null, WmsReceivable::getOrderId, bo.getOrderId());
|
||
lqw.eq(bo.getDueDate() != null, WmsReceivable::getDueDate, bo.getDueDate());
|
||
lqw.eq(bo.getAmount() != null, WmsReceivable::getAmount, bo.getAmount());
|
||
lqw.eq(bo.getPaidAmount() != null, WmsReceivable::getPaidAmount, bo.getPaidAmount());
|
||
lqw.eq(bo.getBalanceAmount() != null, WmsReceivable::getBalanceAmount, bo.getBalanceAmount());
|
||
lqw.eq(StringUtils.isNotBlank(bo.getStatus()), WmsReceivable::getStatus, bo.getStatus());
|
||
return lqw;
|
||
}
|
||
|
||
/**
|
||
* 新增应收款管理(宽松版)
|
||
*/
|
||
@Override
|
||
public Boolean insertByBo(WmsReceivableBo bo) {
|
||
WmsReceivable add = BeanUtil.toBean(bo, WmsReceivable.class);
|
||
validEntityBeforeSave(add);
|
||
boolean flag = baseMapper.insert(add) > 0;
|
||
if (flag) {
|
||
bo.setReceivableId(add.getReceivableId());
|
||
}
|
||
return flag;
|
||
}
|
||
|
||
/**
|
||
* 修改应收款管理(宽松版)
|
||
*/
|
||
@Override
|
||
public Boolean updateByBo(WmsReceivableBo bo) {
|
||
WmsReceivable update = BeanUtil.toBean(bo, WmsReceivable.class);
|
||
validEntityBeforeSave(update);
|
||
return baseMapper.updateById(update) > 0;
|
||
}
|
||
|
||
/**
|
||
* 保存前的数据校验
|
||
*/
|
||
private void validEntityBeforeSave(WmsReceivable entity){
|
||
//TODO 做一些数据校验,如唯一约束
|
||
}
|
||
|
||
/**
|
||
* 批量删除应收款管理(宽松版)
|
||
*/
|
||
@Override
|
||
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
||
if(isValid){
|
||
//TODO 做一些业务上的校验,判断是否需要校验
|
||
}
|
||
return baseMapper.deleteBatchIds(ids) > 0;
|
||
}
|
||
|
||
@Transactional(rollbackFor = Exception.class)
|
||
@Override
|
||
public Boolean updatePaidAmountAndAddJournal(WmsReceivableBo bo) {
|
||
// 1. 更新应收款已收金额
|
||
WmsReceivable receivable = baseMapper.selectById(bo.getReceivableId());
|
||
if (receivable == null) {
|
||
throw new RuntimeException("应收款记录不存在");
|
||
}
|
||
// bo.getPaidAmount()传入的是变化量
|
||
BigDecimal changePaidAmount = bo.getPaidAmount();
|
||
BigDecimal newPaidAmount = receivable.getPaidAmount().add(changePaidAmount);
|
||
|
||
WmsReceivable updateWmsReceivable = new WmsReceivable();
|
||
updateWmsReceivable.setReceivableId(bo.getReceivableId());
|
||
updateWmsReceivable.setPaidAmount(newPaidAmount);
|
||
if(receivable.getPaidAmount().compareTo(BigDecimal.ZERO) == 0
|
||
&& changePaidAmount.compareTo(BigDecimal.ZERO) > 0){
|
||
updateWmsReceivable.setStatus("部分支付");
|
||
}
|
||
if(newPaidAmount.compareTo(receivable.getAmount()) == 0){
|
||
updateWmsReceivable.setStatus("已结清");
|
||
}
|
||
int countFlag = baseMapper.updateById(updateWmsReceivable);
|
||
|
||
// 2. 新增资金日记账记录
|
||
WmsJournal journal = new WmsJournal();
|
||
journal.setJournalDate(new Date());
|
||
journal.setSummary("客户付款");
|
||
journal.setTransType("收入");
|
||
journal.setCounterpart(customerMapper.selectById(receivable.getCustomerId()).getName());
|
||
journal.setIncomeAmount(changePaidAmount);
|
||
journal.setExpenseAmount(BigDecimal.ZERO);
|
||
wmsJournalService.computeBalance(journal);
|
||
journal.setRemark("应收款ID: " + bo.getReceivableId());
|
||
countFlag += journalMapper.insert(journal);
|
||
return countFlag == 2;
|
||
}
|
||
}
|