Merge remote-tracking branch 'origin/master'

This commit is contained in:
GYJ
2025-04-06 18:06:14 +08:00
30 changed files with 824 additions and 62 deletions

View File

@@ -0,0 +1,18 @@
package com.czg.service.product.mapper;
import com.czg.product.vo.ShopVendorBillPayRecordVO;
import com.mybatisflex.core.BaseMapper;
import com.czg.product.entity.ConsPayRecord;
import java.util.List;
/**
* 耗材付款记录 映射层。
*
* @author zs
* @since 2025-04-03
*/
public interface ConsPayRecordMapper extends BaseMapper<ConsPayRecord> {
List<ShopVendorBillPayRecordVO> selectByFlowId(Long shopId, Long flowId);
}

View File

@@ -3,8 +3,13 @@ package com.czg.service.product.mapper;
import com.czg.product.entity.ConsStockFlow;
import com.czg.product.param.ConsInfoParam;
import com.czg.product.vo.ConsStatisticsVo;
import com.czg.product.vo.ShopVendorBillRecordVO;
import com.mybatisflex.core.BaseMapper;
import jakarta.validation.constraints.NotEmpty;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 耗材库存变动记录
@@ -15,4 +20,8 @@ import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface ConsStockFlowMapper extends BaseMapper<ConsStockFlow> {
ConsStatisticsVo getConsStatistics(ConsInfoParam param);
}
List<ShopVendorBillRecordVO> selectByVendorId(@Param("shopId") Long shopId, @Param("vendorId") Integer vendorId);
List<ConsStockFlow> selectUnPaid(@Param("shopId") Long shopId, @Param("vendorIds") @NotEmpty List<Long> vendorIds);
}

View File

@@ -1,8 +1,13 @@
package com.czg.service.product.mapper;
import com.czg.product.entity.ShopVendor;
import com.czg.product.vo.ShopVendorBillVO;
import com.czg.product.vo.ShopVendorSummaryVO;
import com.mybatisflex.core.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 供应商
@@ -13,4 +18,8 @@ import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface ShopVendorMapper extends BaseMapper<ShopVendor> {
}
ShopVendorSummaryVO summary(@Param("shopId") Long shopId);
List<ShopVendorBillVO> bill(@Param("shopId") Long shopId);
}

View File

@@ -0,0 +1,28 @@
package com.czg.service.product.service.impl;
import com.czg.product.vo.ShopVendorBillPayRecordVO;
import com.czg.utils.PageUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.czg.product.entity.ConsPayRecord;
import com.czg.product.service.ConsPayRecordService;
import com.czg.service.product.mapper.ConsPayRecordMapper;
import org.springframework.stereotype.Service;
/**
* 耗材付款记录 服务层实现。
*
* @author zs
* @since 2025-04-03
*/
@Service
public class ConsPayRecordServiceImpl extends ServiceImpl<ConsPayRecordMapper, ConsPayRecord> implements ConsPayRecordService{
@Override
public Page<ShopVendorBillPayRecordVO> getByFlowId(Long shopId, Long flowId) {
PageHelper.startPage(PageUtil.buildPageHelp());
return PageUtil.convert(new PageInfo<>(mapper.selectByFlowId(shopId, flowId)));
}
}

View File

@@ -1,21 +1,38 @@
package com.czg.service.product.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.czg.enums.DeleteEnum;
import com.czg.exception.ApiNotPrintException;
import com.czg.exception.CzgException;
import com.czg.product.dto.ShopVendorBillPayDTO;
import com.czg.product.dto.ShopVendorDTO;
import com.czg.product.entity.ConsPayRecord;
import com.czg.product.entity.ConsStockFlow;
import com.czg.product.entity.ShopVendor;
import com.czg.product.service.ConsPayRecordService;
import com.czg.product.service.ConsStockFlowService;
import com.czg.product.service.ShopVendorService;
import com.czg.product.vo.ShopVendorBillPayRecordVO;
import com.czg.product.vo.ShopVendorBillRecordVO;
import com.czg.product.vo.ShopVendorBillVO;
import com.czg.product.vo.ShopVendorSummaryVO;
import com.czg.sa.StpKit;
import com.czg.service.product.mapper.ConsStockFlowMapper;
import com.czg.service.product.mapper.ShopVendorMapper;
import com.czg.utils.PageUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.core.update.UpdateChain;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
/**
@@ -26,6 +43,12 @@ import java.util.List;
*/
@Service
public class ShopVendorServiceImpl extends ServiceImpl<ShopVendorMapper, ShopVendor> implements ShopVendorService {
@Resource
private ConsStockFlowMapper consStockFlowMapper;
@Resource
private ConsStockFlowService consStockFlowService;
@Resource
private ConsPayRecordService consPayRecordService;
private QueryWrapper buildQueryWrapper(ShopVendorDTO param) {
QueryWrapper queryWrapper = PageUtil.buildSortQueryWrapper();
@@ -93,4 +116,73 @@ public class ShopVendorServiceImpl extends ServiceImpl<ShopVendorMapper, ShopVen
.update();
}
}
@Override
public ShopVendorSummaryVO summary(Long shopId) {
return mapper.summary(shopId);
}
@Override
public Page<ShopVendorBillVO> billList(Long shopId) {
PageHelper.startPage(PageUtil.buildPageHelp());
return PageUtil.convert(new PageInfo<>(mapper.bill(shopId)));
}
@Override
public Page<ShopVendorBillRecordVO> billRecord(Long shopId, Integer vendorId) {
PageHelper.startPage(PageUtil.buildPageHelp());
return PageUtil.convert(new PageInfo<>(consStockFlowMapper.selectByVendorId(shopId, vendorId)));
}
@Override
public Boolean pay(Long shopId, ShopVendorBillPayDTO payDTO) {
// 批量付款
if (payDTO.getFlowIdList().size() > 1) {
List<ConsStockFlow> stockFlows = consStockFlowMapper.selectUnPaid(shopId, payDTO.getFlowIdList());
BigDecimal unPaidAmount = BigDecimal.ZERO;
ArrayList<ConsPayRecord> records = new ArrayList<>();
for (ConsStockFlow item : stockFlows) {
unPaidAmount = unPaidAmount.add(item.getAmountPayable().subtract(item.getActualPaymentAmount()));
item.setActualPaymentAmount(item.getAmountPayable());
records.add(new ConsPayRecord().setShopId(shopId).setVendorId(item.getVendorId()).setType(payDTO.getType())
.setAmount(item.getAmountPayable().subtract(item.getActualPaymentAmount()))
.setFlowId(item.getId()).setUserId(StpKit.USER.getLoginIdAsLong()).setCreateTime(DateUtil.date().toLocalDateTime()));
}
if (unPaidAmount.compareTo(payDTO.getAmount()) != 0) {
throw new ApiNotPrintException("批量付款应全部付款");
}
consPayRecordService.saveBatch(records);
return consStockFlowService.updateBatch(stockFlows);
}else {
ConsStockFlow stockFlow = consStockFlowMapper.selectOneByQuery(new QueryWrapper().eq(ConsStockFlow::getShopId, shopId).eq(ConsStockFlow::getId, payDTO.getFlowIdList().getFirst()));
if (stockFlow == null) {
throw new ApiNotPrintException("付款账单不存在");
}
if (stockFlow.getAmountPayable().compareTo(stockFlow.getActualPaymentAmount()) <= 0) {
throw new ApiNotPrintException("次账单已付款完成");
}
if (payDTO.getAmount().compareTo(stockFlow.getAmountPayable().subtract(stockFlow.getActualPaymentAmount())) > 0) {
throw new ApiNotPrintException("付款金额不应超过待付款金额");
}
ConsPayRecord consPayRecord = BeanUtil.copyProperties(payDTO, ConsPayRecord.class);
consPayRecord.setShopId(shopId);
consPayRecord.setVendorId(stockFlow.getVendorId());
consPayRecord.setFlowId(payDTO.getFlowIdList().getFirst());
consPayRecord.setUserId(StpKit.USER.getLoginIdAsLong());
consPayRecordService.save(consPayRecord);
stockFlow.setActualPaymentAmount(stockFlow.getActualPaymentAmount().add(payDTO.getAmount()));
return consStockFlowMapper.update(stockFlow) > 0;
}
}
@Override
public Page<ShopVendorBillPayRecordVO> payRecord(Long shopId, Long flowId) {
return consPayRecordService.getByFlowId(shopId, flowId);
}
}

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.czg.service.product.mapper.ConsPayRecordMapper">
<select id="selectByFlowId" resultType="com.czg.product.vo.ShopVendorBillPayRecordVO">
select a.*, b.con_name, b.purchase_price, b.in_out_number, c.account, c.nick_name, c.id
from tb_cons_pay_record as a
left join tb_cons_stock_flow as b on a.flow_id = b.id
left join sys_user as c on c.id = a.user_id
where a.flow_id = #{flowId} and a.shop_id=#{shopId}
</select>
</mapper>

View File

@@ -5,16 +5,16 @@
<select id="getConsStatistics" resultType="com.czg.product.vo.ConsStatisticsVo">
SELECT
sum( CASE WHEN t1.in_out_type = 'in' then t1.in_out_number end) AS inSumTotal,
sum( CASE WHEN t1.in_out_item = 'win-in' THEN t1.in_out_number END ) AS winInNum,
sum( CASE WHEN t1.in_out_item = 'manual-in' THEN t1.in_out_number END ) AS stockInNum,
sum( CASE WHEN t1.in_out_type = 'out' then abs(t1.in_out_number) end) AS outSumTotal,
sum( CASE WHEN t1.in_out_item = 'loss-out' THEN abs(t1.in_out_number) END ) AS lossOutNum,
abs(sum( CASE WHEN t1.in_out_item = 'order-out' THEN t1.in_out_number END )) AS consumeNum,
sum( CASE WHEN t1.in_out_item = 'damage-out' THEN abs(t1.in_out_number) END ) AS damageNum,
sum( CASE WHEN t1.in_out_item = 'manual-out' THEN abs(t1.in_out_number) END ) AS stockOutNum
sum( CASE WHEN t1.in_out_type = 'in' then t1.in_out_number end) AS inSumTotal,
sum( CASE WHEN t1.in_out_item = 'win-in' THEN t1.in_out_number END ) AS winInNum,
sum( CASE WHEN t1.in_out_item = 'manual-in' THEN t1.in_out_number END ) AS stockInNum,
sum( CASE WHEN t1.in_out_type = 'out' then abs(t1.in_out_number) end) AS outSumTotal,
sum( CASE WHEN t1.in_out_item = 'loss-out' THEN abs(t1.in_out_number) END ) AS lossOutNum,
abs(sum( CASE WHEN t1.in_out_item = 'order-out' THEN t1.in_out_number END )) AS consumeNum,
sum( CASE WHEN t1.in_out_item = 'damage-out' THEN abs(t1.in_out_number) END ) AS damageNum,
sum( CASE WHEN t1.in_out_item = 'manual-out' THEN abs(t1.in_out_number) END ) AS stockOutNum
FROM
tb_cons_stock_flow t1
tb_cons_stock_flow t1
LEFT JOIN tb_cons_info t2 on t1.con_id = t2.id
where t1.shop_id = #{shopId}
<if test="id != null">
@@ -35,4 +35,25 @@
]]>
</if>
</select>
</mapper>
<select id="selectByVendorId" resultType="com.czg.product.vo.ShopVendorBillRecordVO">
SELECT id,
con_name,
purchase_price,
in_out_number,
amount_payable,
actual_payment_amount,
remark,
create_time,
(amount_payable - actual_payment_amount) as unPaidAmount
FROM tb_cons_stock_flow
WHERE shop_id = #{shopId}
and vendor_id = #{vendorId}
</select>
<select id="selectUnPaid" resultType="com.czg.product.entity.ConsStockFlow">
select * from tb_cons_stock_flow where amount_payable > actual_payment_amount and shop_id=#{shopId}
<foreach collection="vendorIds" item="id" open="and vendor_id in (" separator=",">
#{id}
</foreach>
</select>
</mapper>

View File

@@ -3,4 +3,34 @@
<mapper namespace="com.czg.service.product.mapper.ShopVendorMapper">
</mapper>
<select id="summary" resultType="com.czg.product.vo.ShopVendorSummaryVO">
SELECT vendor_id,
sum(amount_payable) AS amountPayable,
sum(CASE
WHEN create_time BETWEEN DATE_FORMAT(NOW(), '%Y-%m-01') AND LAST_DAY(NOW())
THEN amount_payable END) AS mouthAmountPayable,
sum(actual_payment_amount) AS actualPaymentAmount,
sum(CASE
WHEN create_time BETWEEN DATE_FORMAT(NOW(), '%Y-%m-01') AND LAST_DAY(NOW())
THEN actual_payment_amount END) AS mouthActualPaymentAmount,
sum(amount_payable - actual_payment_amount) AS unPaidAmount,
sum(CASE
WHEN create_time BETWEEN DATE_FORMAT(NOW(), '%Y-%m-01') AND LAST_DAY(NOW())
THEN amount_payable - actual_payment_amount END) AS mouthUnPaidAmount,
remark
FROM tb_cons_stock_flow
WHERE shop_id = #{shopId}
</select>
<select id="bill" resultType="com.czg.product.vo.ShopVendorBillVO">
select tb_cons_stock_flow.vendor_id as vendorId,
tb_shop_vendor.`name`,
sum(tb_cons_stock_flow.amount_payable) as amountPayable,
sum(tb_cons_stock_flow.actual_payment_amount) as actualPaymentAmount,
sum(tb_cons_stock_flow.amount_payable) - sum(tb_cons_stock_flow.actual_payment_amount) as unPaidAmount,
tb_cons_stock_flow.remark
from tb_cons_stock_flow
left join tb_shop_vendor on tb_cons_stock_flow.vendor_id = tb_shop_vendor.id
where tb_cons_stock_flow.shop_id = #{shopId}
GROUP BY tb_cons_stock_flow.vendor_id
</select>
</mapper>