挂账接口
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package com.czg.controller.admin;
|
||||
|
||||
import com.czg.log.annotation.OperationLog;
|
||||
import com.czg.order.dto.CreditBuyerDTO;
|
||||
import com.czg.order.entity.CreditBuyer;
|
||||
import com.czg.order.param.CreditBuyerQueryParam;
|
||||
import com.czg.order.param.CreditBuyerRepaymentParam;
|
||||
@@ -32,8 +31,8 @@ public class CreditBuyerController {
|
||||
@GetMapping("page")
|
||||
@OperationLog("挂账人-分页")
|
||||
//@SaAdminCheckPermission("creditBuyer:page")
|
||||
public CzgResult<Page<CreditBuyerDTO>> getCreditBuyerPage(CreditBuyerQueryParam param) {
|
||||
Page<CreditBuyerDTO> data = creditBuyerService.getCreditBuyerPage(param);
|
||||
public CzgResult<Page<CreditBuyer>> getCreditBuyerPage(CreditBuyerQueryParam param) {
|
||||
Page<CreditBuyer> data = creditBuyerService.getCreditBuyerPage(param);
|
||||
return CzgResult.success(data);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.czg.order.param;
|
||||
|
||||
import com.alibaba.fastjson2.annotation.JSONField;
|
||||
import com.czg.utils.CzgStrUtils;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
@@ -23,24 +24,39 @@ public class CreditBuyerQueryParam implements Serializable {
|
||||
@JSONField(serialize = false)
|
||||
private String id;
|
||||
/**
|
||||
* 关键字
|
||||
* 挂账人
|
||||
*/
|
||||
private String keywords;
|
||||
private String debtor;
|
||||
/**
|
||||
* 还款状态 unpaid-未还款 partial-部分还款 paid-已还清
|
||||
* 手机号
|
||||
*/
|
||||
private String repaymentStatus;
|
||||
/**
|
||||
* 责任人
|
||||
*/
|
||||
private String responsiblePerson;
|
||||
private String mobile;
|
||||
/**
|
||||
* 状态 1-启用 0-停用
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 还款状态 1 有欠款 2 无欠款
|
||||
*/
|
||||
private Integer repaymentStatus;
|
||||
/**
|
||||
* 店铺id
|
||||
*/
|
||||
@JSONField(serialize = false)
|
||||
private Long shopId;
|
||||
|
||||
public String getMobile() {
|
||||
return CzgStrUtils.getStrOrNull(mobile);
|
||||
}
|
||||
|
||||
|
||||
public String getDebtor() {
|
||||
return CzgStrUtils.getStrOrNull(debtor);
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return CzgStrUtils.getStrOrNull(id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.czg.order.service;
|
||||
|
||||
import com.czg.order.dto.CreditBuyerDTO;
|
||||
import com.czg.order.entity.CreditBuyer;
|
||||
import com.czg.order.param.CreditBuyerQueryParam;
|
||||
import com.czg.order.param.CreditBuyerRepaymentParam;
|
||||
@@ -15,7 +14,7 @@ import com.mybatisflex.core.service.IService;
|
||||
* @since 1.0 2025-03-04
|
||||
*/
|
||||
public interface CreditBuyerService extends IService<CreditBuyer> {
|
||||
Page<CreditBuyerDTO> getCreditBuyerPage(CreditBuyerQueryParam param);
|
||||
Page<CreditBuyer> getCreditBuyerPage(CreditBuyerQueryParam param);
|
||||
|
||||
|
||||
void addCreditBuyer(CreditBuyer dto);
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
package com.czg.service.order.mapper;
|
||||
|
||||
import com.czg.order.dto.CreditBuyerDTO;
|
||||
import com.czg.order.entity.CreditBuyer;
|
||||
import com.czg.order.param.CreditBuyerQueryParam;
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 挂账人
|
||||
*
|
||||
@@ -17,6 +13,5 @@ import java.util.List;
|
||||
@Mapper
|
||||
public interface CreditBuyerMapper extends BaseMapper<CreditBuyer> {
|
||||
|
||||
List<CreditBuyerDTO> findCreditBuyerList(CreditBuyerQueryParam param);
|
||||
|
||||
}
|
||||
@@ -10,7 +10,6 @@ import cn.hutool.core.util.NumberUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.czg.constants.SystemConstants;
|
||||
import com.czg.exception.CzgException;
|
||||
import com.czg.order.dto.CreditBuyerDTO;
|
||||
import com.czg.order.dto.CreditBuyerOrderDTO;
|
||||
import com.czg.order.entity.CreditBuyer;
|
||||
import com.czg.order.entity.CreditBuyerOrder;
|
||||
@@ -25,10 +24,8 @@ import com.czg.service.order.mapper.CreditBuyerMapper;
|
||||
import com.czg.service.order.mapper.CreditBuyerOrderMapper;
|
||||
import com.czg.service.order.mapper.CreditPaymentRecordMapper;
|
||||
import com.czg.utils.PageUtil;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.github.pagehelper.PageParam;
|
||||
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 jakarta.annotation.Resource;
|
||||
@@ -56,13 +53,22 @@ public class CreditBuyerServiceImpl extends ServiceImpl<CreditBuyerMapper, Credi
|
||||
private CreditBuyerOrderMapper creditBuyerOrderMapper;
|
||||
|
||||
@Override
|
||||
public Page<CreditBuyerDTO> getCreditBuyerPage(CreditBuyerQueryParam param) {
|
||||
PageParam pageParam = PageUtil.buildPageHelp();
|
||||
PageHelper.startPage(pageParam.getPageNum(), pageParam.getPageSize(), pageParam.getOrderBy());
|
||||
public Page<CreditBuyer> getCreditBuyerPage(CreditBuyerQueryParam param) {
|
||||
|
||||
Long shopId = StpKit.USER.getShopId(0L);
|
||||
param.setShopId(shopId);
|
||||
PageInfo<CreditBuyerDTO> pageInfo = new PageInfo<>(super.mapper.findCreditBuyerList(param));
|
||||
return PageUtil.convert(pageInfo);
|
||||
QueryWrapper queryWrapper = query().eq(CreditBuyer::getShopId, shopId)
|
||||
.like(CreditBuyer::getMobile, param.getMobile())
|
||||
.like(CreditBuyer::getDebtor, param.getDebtor())
|
||||
.eq(CreditBuyer::getIsDel, SystemConstants.OneZero.ZERO);
|
||||
if (param.getRepaymentStatus() != null) {
|
||||
if (param.getRepaymentStatus() == 1) {
|
||||
queryWrapper.where(CreditBuyer::getAccountBalance).gt(CreditBuyer::getCreditAmount);
|
||||
}else {
|
||||
queryWrapper.where(CreditBuyer::getAccountBalance).le(CreditBuyer::getCreditAmount);
|
||||
}
|
||||
}
|
||||
return page(PageUtil.buildPage(), queryWrapper);
|
||||
}
|
||||
|
||||
private void commonVerify(CreditBuyer dto) {
|
||||
@@ -201,7 +207,7 @@ public class CreditBuyerServiceImpl extends ServiceImpl<CreditBuyerMapper, Credi
|
||||
throw new CzgException("没有需要还款的订单");
|
||||
}
|
||||
int repaymentCount = 0;
|
||||
List<CreditBuyerOrderDTO> orderList = list.stream().sorted(Comparator.comparing(CreditBuyerOrderDTO::getOrderId)).collect(Collectors.toList());
|
||||
List<CreditBuyerOrderDTO> orderList = list.stream().sorted(Comparator.comparing(CreditBuyerOrderDTO::getOrderId)).toList();
|
||||
for (CreditBuyerOrderDTO item : orderList) {
|
||||
// 未付款金额
|
||||
BigDecimal unpaidAmount = item.getUnpaidAmount();
|
||||
|
||||
@@ -3,74 +3,4 @@
|
||||
|
||||
<mapper namespace="com.czg.service.order.mapper.CreditBuyerMapper">
|
||||
|
||||
<sql id="view_credit_buyer_order_count">
|
||||
(SELECT
|
||||
tb.credit_buyer_id AS credit_buyer_id,
|
||||
tb.status AS status,
|
||||
count( 0 ) AS count
|
||||
FROM
|
||||
<include refid="view_credit_buyer_order"/>
|
||||
tb
|
||||
GROUP BY tb.credit_buyer_id,tb.status)
|
||||
</sql>
|
||||
|
||||
<sql id="view_credit_buyer_order">
|
||||
(SELECT t1.id AS id,
|
||||
t1.credit_buyer_id AS credit_buyer_id,
|
||||
t1.order_id AS order_id,
|
||||
t2.pay_amount - t2.refund_amount AS pay_amount,
|
||||
t1.paid_amount AS paid_amount,
|
||||
(t2.pay_amount - t2.refund_amount) - t1.paid_amount AS unpaid_amount,
|
||||
t1.status AS status,
|
||||
t2.create_time AS create_time,
|
||||
t1.last_payment_time AS last_payment_time,
|
||||
t1.last_payment_method AS last_payment_method,
|
||||
t1.remark AS remark
|
||||
FROM tb_credit_buyer_order t1
|
||||
LEFT JOIN tb_order_info t2 ON t1.order_id = t2.id)
|
||||
</sql>
|
||||
|
||||
<select id="findCreditBuyerList" resultType="com.czg.order.dto.CreditBuyerDTO">
|
||||
select x1.*,
|
||||
x2.shop_name,
|
||||
ifnull(x3.owed_amount, 0 ) as owed_amount,
|
||||
ifnull(x3.accumulate_amount,0) as accumulate_amount
|
||||
from tb_credit_buyer x1
|
||||
left join tb_shop_info x2 on x1.shop_id = x2.id
|
||||
left join (select t.credit_buyer_id,ifnull(sum(t.unpaid_amount),0) as owed_amount,ifnull(sum(t.pay_amount),0) as
|
||||
accumulate_amount from
|
||||
<include refid="view_credit_buyer_order"/>
|
||||
t
|
||||
group by t.credit_buyer_id) x3 on x1.id = x3.credit_buyer_id
|
||||
<where>
|
||||
and x1.is_del = 0
|
||||
and x1.shop_id = #{shopId}
|
||||
<if test="id !=null and id != ''">
|
||||
and x1.id = #{id}
|
||||
</if>
|
||||
<if test="responsiblePerson !=null and responsiblePerson != ''">
|
||||
and x1.responsible_person like concat('%',#{responsiblePerson},'%')
|
||||
</if>
|
||||
<if test="status !=null">
|
||||
and x1.status = #{status}
|
||||
</if>
|
||||
<if test="keywords !=null and keywords != ''">
|
||||
and (x1.debtor like concat('%',#{keywords},'%') or x1.mobile like concat('%',#{keywords},'%'))
|
||||
</if>
|
||||
<if test="repaymentStatus !=null and repaymentStatus != ''">
|
||||
<if test="repaymentStatus == 'unpaid'">
|
||||
and 0 < ifnull((select x.count from <include refid="view_credit_buyer_order_count"/> x where x.credit_buyer_id = x1.id and x.status = 'unpaid'),0)
|
||||
and 0 = ifnull((select x.count from <include refid="view_credit_buyer_order_count"/> x where x.credit_buyer_id = x1.id and x.status = 'partial'),0)
|
||||
</if>
|
||||
<if test="repaymentStatus == 'partial'">
|
||||
and 0 < ifnull((select x.count from <include refid="view_credit_buyer_order_count"/> x where x.credit_buyer_id = x1.id and x.status = 'partial'),0)
|
||||
</if>
|
||||
<if test="repaymentStatus == 'paid'">
|
||||
and 0 = ifnull((select sum(x.count) from <include refid="view_credit_buyer_order_count"/> x where x.credit_buyer_id = x1.id and x.status in ('unpaid','partial')),0)
|
||||
</if>
|
||||
</if>
|
||||
</where>
|
||||
order by x1.status desc,x1.id desc
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user