|
|
|
@ -1,10 +1,12 @@ |
|
|
|
package com.example.demo.serviceImpl.cash; |
|
|
|
|
|
|
|
import com.example.demo.config.RabbitMQConfig; |
|
|
|
import com.example.demo.domain.entity.CashRecord; |
|
|
|
import com.example.demo.domain.entity.GOrder; |
|
|
|
import com.example.demo.domain.entity.RechargeActivity; |
|
|
|
import com.example.demo.domain.entity.User; |
|
|
|
import com.example.demo.domain.vo.cash.CashCollection; |
|
|
|
import com.example.demo.domain.vo.cash.CashCollectionMessage; |
|
|
|
import com.example.demo.domain.vo.coin.Result; |
|
|
|
import com.example.demo.mapper.cash.CashCollectionMapper; |
|
|
|
import com.example.demo.mapper.coin.MarketMapper; |
|
|
|
@ -12,6 +14,7 @@ import com.example.demo.service.cash.CashCollectionService; |
|
|
|
import com.github.pagehelper.PageHelper; |
|
|
|
import com.github.pagehelper.PageInfo; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.amqp.rabbit.core.RabbitTemplate; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
@ -26,7 +29,7 @@ import java.util.UUID; |
|
|
|
/** |
|
|
|
* @program: gold-java |
|
|
|
* @ClassName cashCollectionServiceImpl |
|
|
|
* @description: |
|
|
|
* @description: 处理收款相关业务逻辑 |
|
|
|
* @author: Ethan |
|
|
|
* @create: 2025−09-26 11:23 |
|
|
|
* @Version 1.0 |
|
|
|
@ -39,49 +42,53 @@ public class CashCollectionServiceImpl implements CashCollectionService { |
|
|
|
private CashCollectionMapper cashCollectionMapper; |
|
|
|
@Autowired |
|
|
|
private MarketMapper marketMapper; |
|
|
|
@Autowired |
|
|
|
private RabbitTemplate rabbitTemplate; |
|
|
|
|
|
|
|
//新增收款订单 |
|
|
|
@Override |
|
|
|
public String add(CashCollection cashCollection) { |
|
|
|
if (cashCollection.getJwcode()==null){ |
|
|
|
if (cashCollection.getJwcode() == null) { |
|
|
|
throw new IllegalArgumentException("精网号不能为空"); |
|
|
|
} |
|
|
|
if(cashCollection.getJwcode()<10000000||cashCollection.getJwcode()>99999999){ |
|
|
|
if (cashCollection.getJwcode() < 10000000 || cashCollection.getJwcode() > 99999999) { |
|
|
|
throw new IllegalArgumentException("精网号必须为8位"); |
|
|
|
} |
|
|
|
if(cashCollection.getName()== null){ |
|
|
|
if (cashCollection.getName() == null) { |
|
|
|
throw new IllegalArgumentException("客户姓名不能为空"); |
|
|
|
} |
|
|
|
if(cashCollection.getActivity()== null){ |
|
|
|
if (cashCollection.getActivity() == null) { |
|
|
|
throw new IllegalArgumentException("活动不能为空"); |
|
|
|
} |
|
|
|
if(cashCollection.getGoodsName()== null){ |
|
|
|
if (cashCollection.getGoodsName() == null) { |
|
|
|
throw new IllegalArgumentException("商品名不能为空"); |
|
|
|
} |
|
|
|
if (cashCollection.getGoodsName().equals("金币充值")){ |
|
|
|
if( cashCollection.getPermanentGold()== 0 && cashCollection.getFreeGold()== 0){ |
|
|
|
throw new IllegalArgumentException("金币数量不能为空");} |
|
|
|
if (cashCollection.getGoodsName().equals("金币充值")) { |
|
|
|
if (cashCollection.getPermanentGold() == 0 && cashCollection.getFreeGold() == 0) { |
|
|
|
throw new IllegalArgumentException("金币数量不能为空"); |
|
|
|
} |
|
|
|
} |
|
|
|
if (!cashCollection.getGoodsName().equals("金币充值")){ |
|
|
|
if( cashCollection.getGoodNum()== 0 ){ |
|
|
|
throw new IllegalArgumentException("产品数量不能为空");} |
|
|
|
if(cashCollection.getNumUnit()== null){ |
|
|
|
if (!cashCollection.getGoodsName().equals("金币充值")) { |
|
|
|
if (cashCollection.getGoodNum() == 0) { |
|
|
|
throw new IllegalArgumentException("产品数量不能为空"); |
|
|
|
} |
|
|
|
if (cashCollection.getNumUnit() == null) { |
|
|
|
throw new IllegalArgumentException("数量单位不能为空"); |
|
|
|
} |
|
|
|
} |
|
|
|
if(cashCollection.getPaymentCurrency()== null){ |
|
|
|
if (cashCollection.getPaymentCurrency() == null) { |
|
|
|
throw new IllegalArgumentException("支付币种不能为空"); |
|
|
|
} |
|
|
|
if(cashCollection.getPaymentAmount()== null){ |
|
|
|
if (cashCollection.getPaymentAmount() == null) { |
|
|
|
throw new IllegalArgumentException("支付金额不能为空"); |
|
|
|
} |
|
|
|
if (cashCollection.getPayType()== null){ |
|
|
|
if (cashCollection.getPayType() == null) { |
|
|
|
throw new IllegalArgumentException("支付方式不能为空"); |
|
|
|
} |
|
|
|
if (cashCollection.getReceivedMarket()== null){ |
|
|
|
if (cashCollection.getReceivedMarket() == null) { |
|
|
|
throw new IllegalArgumentException("到账地区不能为空"); |
|
|
|
} |
|
|
|
if(cashCollection.getPayTime()== null){ |
|
|
|
if (cashCollection.getPayTime() == null) { |
|
|
|
throw new IllegalArgumentException("付款时间不能为空"); |
|
|
|
} |
|
|
|
//生成订单号后半部分 |
|
|
|
@ -113,9 +120,25 @@ public class CashCollectionServiceImpl implements CashCollectionService { |
|
|
|
//cashRecord.setMarket(cashCollectionMapper.getMarketByJwcode(cashRecord.getJwcode())); |
|
|
|
//插入新收款订单 |
|
|
|
cashCollectionMapper.add(cashRecord); |
|
|
|
// 发送收款创建消息 |
|
|
|
CashCollectionMessage message = new CashCollectionMessage(); |
|
|
|
message.setId(cashRecord.getId()); |
|
|
|
message.setOrderCode(cashRecord.getOrderCode()); |
|
|
|
message.setStatus(cashRecord.getStatus()); |
|
|
|
message.setStatusDescription("线下财务待审核"); |
|
|
|
message.setMessage("收款订单已创建"); |
|
|
|
message.setSubmitterId(cashRecord.getSubmitterId()); |
|
|
|
// 可以通过 submitterId 查询提交人姓名 |
|
|
|
message.setTimestamp(LocalDateTime.now()); |
|
|
|
|
|
|
|
rabbitTemplate.convertAndSend( |
|
|
|
RabbitMQConfig.CASH_COLLECTION_EXCHANGE, |
|
|
|
"collection.created", |
|
|
|
message |
|
|
|
); |
|
|
|
return "添加成功"; |
|
|
|
} |
|
|
|
|
|
|
|
//撤回未审核的订单 |
|
|
|
@Override |
|
|
|
public String cancel(String orderCode) { |
|
|
|
@ -123,113 +146,157 @@ public class CashCollectionServiceImpl implements CashCollectionService { |
|
|
|
if (cashRecord == null) { |
|
|
|
throw new IllegalArgumentException("订单不存在"); |
|
|
|
} |
|
|
|
if (cashRecord.getStatus() != 0){ |
|
|
|
if (cashRecord.getStatus() != 0) { |
|
|
|
throw new IllegalArgumentException("订单状态不符合条件"); |
|
|
|
} |
|
|
|
//修改订单状态 |
|
|
|
int rows = cashCollectionMapper.updateStatus(orderCode, 5); |
|
|
|
if (rows > 0) { |
|
|
|
// 发送收款撤回消息 |
|
|
|
CashCollectionMessage message = new CashCollectionMessage(); |
|
|
|
message.setId(cashRecord.getId()); |
|
|
|
message.setOrderCode(cashRecord.getOrderCode()); |
|
|
|
message.setStatus(5); |
|
|
|
message.setStatusDescription("手动撤回待编辑提交"); |
|
|
|
message.setMessage("收款订单已撤回"); |
|
|
|
message.setSubmitterId(cashRecord.getSubmitterId()); |
|
|
|
message.setAuditId(cashRecord.getAuditId()); |
|
|
|
message.setTimestamp(LocalDateTime.now()); |
|
|
|
|
|
|
|
rabbitTemplate.convertAndSend( |
|
|
|
RabbitMQConfig.CASH_COLLECTION_EXCHANGE, |
|
|
|
"collection.cancelled", |
|
|
|
message |
|
|
|
); |
|
|
|
} |
|
|
|
return rows > 0 ? "撤回成功" : "撤回失败"; |
|
|
|
} |
|
|
|
|
|
|
|
//编辑并重新提交收款订单 |
|
|
|
@Override |
|
|
|
public String reSubmit(CashRecord cashRecord) { |
|
|
|
if (cashRecord.getJwcode()==null){ |
|
|
|
if (cashRecord.getJwcode() == null) { |
|
|
|
throw new IllegalArgumentException("精网号不能为空"); |
|
|
|
} |
|
|
|
if(cashRecord.getJwcode()<10000000||cashRecord.getJwcode()>99999999){ |
|
|
|
if (cashRecord.getJwcode() < 10000000 || cashRecord.getJwcode() > 99999999) { |
|
|
|
throw new IllegalArgumentException("精网号必须为8位"); |
|
|
|
} |
|
|
|
if(cashRecord.getName()== null){ |
|
|
|
if (cashRecord.getName() == null) { |
|
|
|
throw new IllegalArgumentException("客户姓名不能为空"); |
|
|
|
} |
|
|
|
if(cashRecord.getActivity()== null){ |
|
|
|
if (cashRecord.getActivity() == null) { |
|
|
|
throw new IllegalArgumentException("活动不能为空"); |
|
|
|
} |
|
|
|
if(cashRecord.getGoodsName()== null){ |
|
|
|
if (cashRecord.getGoodsName() == null) { |
|
|
|
throw new IllegalArgumentException("商品名不能为空"); |
|
|
|
} |
|
|
|
if (cashRecord.getGoodsName().equals("金币充值")){ |
|
|
|
if( cashRecord.getPermanentGold()== 0 && cashRecord.getFreeGold()== 0){ |
|
|
|
throw new IllegalArgumentException("金币数量不能为空");} |
|
|
|
if (cashRecord.getGoodsName().equals("金币充值")) { |
|
|
|
if (cashRecord.getPermanentGold() == 0 && cashRecord.getFreeGold() == 0) { |
|
|
|
throw new IllegalArgumentException("金币数量不能为空"); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
if (!cashRecord.getGoodsName().equals("金币充值")){ |
|
|
|
if( cashRecord.getGoodNum()== 0 ){ |
|
|
|
throw new IllegalArgumentException("产品数量不能为空");} |
|
|
|
if(cashRecord.getNumUnit()== null){ |
|
|
|
if (!cashRecord.getGoodsName().equals("金币充值")) { |
|
|
|
if (cashRecord.getGoodNum() == 0) { |
|
|
|
throw new IllegalArgumentException("产品数量不能为空"); |
|
|
|
} |
|
|
|
if (cashRecord.getNumUnit() == null) { |
|
|
|
throw new IllegalArgumentException("数量单位不能为空"); |
|
|
|
} |
|
|
|
} |
|
|
|
if(cashRecord.getPaymentCurrency()== null){ |
|
|
|
if (cashRecord.getPaymentCurrency() == null) { |
|
|
|
throw new IllegalArgumentException("支付币种不能为空"); |
|
|
|
} |
|
|
|
if(cashRecord.getPaymentAmount()== null){ |
|
|
|
if (cashRecord.getPaymentAmount() == null) { |
|
|
|
throw new IllegalArgumentException("支付金额不能为空"); |
|
|
|
} |
|
|
|
if (cashRecord.getPayType()== null){ |
|
|
|
if (cashRecord.getPayType() == null) { |
|
|
|
throw new IllegalArgumentException("支付方式不能为空"); |
|
|
|
} |
|
|
|
if (cashRecord.getReceivedMarket()== null){ |
|
|
|
if (cashRecord.getReceivedMarket() == null) { |
|
|
|
throw new IllegalArgumentException("到账地区不能为空"); |
|
|
|
} |
|
|
|
if(cashRecord.getPayTime()== null){ |
|
|
|
if (cashRecord.getPayTime() == null) { |
|
|
|
throw new IllegalArgumentException("付款时间不能为空"); |
|
|
|
} |
|
|
|
|
|
|
|
CashRecord status=cashCollectionMapper.selectByOrderCode(cashRecord.getOrderCode()); |
|
|
|
if (!status.getStatus().equals(5)){ |
|
|
|
CashRecord status = cashCollectionMapper.selectByOrderCode(cashRecord.getOrderCode()); |
|
|
|
if (!status.getStatus().equals(5)) { |
|
|
|
throw new IllegalArgumentException("只允许编辑已撤回订单"); |
|
|
|
} |
|
|
|
//地区,根据jwcode插入(弃用,插入前调用接口获取地区和姓名,之后前端传入) |
|
|
|
//cashRecord.setMarket(cashCollectionMapper.getMarketByJwcode(cashRecord.getJwcode())); |
|
|
|
int rows = cashCollectionMapper.updateByOrderCode(cashRecord); |
|
|
|
if (rows > 0) { |
|
|
|
// 发送重新提交消息 |
|
|
|
CashCollectionMessage message = new CashCollectionMessage(); |
|
|
|
message.setId(cashRecord.getId()); |
|
|
|
message.setOrderCode(cashRecord.getOrderCode()); |
|
|
|
message.setStatus(0); // 重新提交后状态变为待审核 |
|
|
|
message.setStatusDescription("线下财务待审核"); |
|
|
|
message.setMessage("收款订单已重新提交"); |
|
|
|
message.setSubmitterId(cashRecord.getSubmitterId()); |
|
|
|
message.setTimestamp(LocalDateTime.now()); |
|
|
|
|
|
|
|
rabbitTemplate.convertAndSend( |
|
|
|
RabbitMQConfig.CASH_COLLECTION_EXCHANGE, |
|
|
|
"collection.created", |
|
|
|
message |
|
|
|
); |
|
|
|
} |
|
|
|
return rows > 0 ? "重新提交成功" : "重新提交失败"; |
|
|
|
} |
|
|
|
|
|
|
|
//多条件查询收款订单列表 |
|
|
|
@Override |
|
|
|
public PageInfo<CashCollection> selectCollection(Integer pageNum, Integer pageSize, CashCollection cashCollection) { |
|
|
|
//将操作人的地区列表改为id |
|
|
|
/* //将操作人的地区列表改为id |
|
|
|
List<String> markets = marketMapper.getMarketIds(cashCollection.getMarkets()); |
|
|
|
if (markets.contains("9") || markets.contains("9999")){ |
|
|
|
markets=null; |
|
|
|
} |
|
|
|
if (markets.contains("9") || markets.contains("9999")) { |
|
|
|
markets = null; |
|
|
|
}*/ |
|
|
|
// cashCollection.setReceivedMarket(marketMapper.getMarketId(cashCollection.getReceivedMarket())); |
|
|
|
if (cashCollection.getCashRoleId()==2) { |
|
|
|
if (cashCollection.getCashRoleId() == 2) { |
|
|
|
//角色是总部时,若不特地传状态,传1346,sql处理为(1,3,4,6)筛选, |
|
|
|
if(cashCollection.getStatus()==null){ |
|
|
|
cashCollection.setStatus(1346);} |
|
|
|
if (cashCollection.getStatus() == null) { |
|
|
|
cashCollection.setStatus(1346); |
|
|
|
} |
|
|
|
cashCollection.setSubmitterId(null); |
|
|
|
cashCollection.setReceivedMarket(null); |
|
|
|
cashCollection.setSubmitterMarket(null); |
|
|
|
} |
|
|
|
if (cashCollection.getCashRoleId()==1){ |
|
|
|
if (cashCollection.getCashRoleId() == 1) { |
|
|
|
//角色是地方财务,提交人置空不设筛选条件,仅按收款地区、提交人地区筛选() |
|
|
|
|
|
|
|
if(cashCollection.getStatus()==null){ |
|
|
|
cashCollection.setStatus(123460);} |
|
|
|
if (cashCollection.getStatus() == null) { |
|
|
|
cashCollection.setStatus(123460); |
|
|
|
} |
|
|
|
//状态为待审核和已驳回时按照提交人地区筛选 |
|
|
|
if (cashCollection.getStatus()==0||cashCollection.getStatus()==2){ |
|
|
|
cashCollection.setReceivedMarket(null);} |
|
|
|
if (cashCollection.getStatus() == 0 || cashCollection.getStatus() == 2) { |
|
|
|
cashCollection.setReceivedMarket(null); |
|
|
|
} |
|
|
|
//状态为已通过和Link通过时,按收款地区筛选 |
|
|
|
if (cashCollection.getStatus()==13){ |
|
|
|
cashCollection.setSubmitterMarket(null);} |
|
|
|
if (cashCollection.getStatus() == 13) { |
|
|
|
cashCollection.setSubmitterMarket(null); |
|
|
|
} |
|
|
|
cashCollection.setSubmitterId(null); |
|
|
|
//状态为46,已通过和已退款,满足收款地区或提交人地区即可, |
|
|
|
|
|
|
|
} |
|
|
|
if (cashCollection.getCashRoleId()==0){ |
|
|
|
if (cashCollection.getCashRoleId() == 0) { |
|
|
|
//角色是地方财务,提交人置空不设筛选条件---仅当角色是0 地方客服时,按提交人筛选 |
|
|
|
if(cashCollection.getStatus()==null){ |
|
|
|
cashCollection.setStatus(1234560);} |
|
|
|
if (cashCollection.getStatus() == null) { |
|
|
|
cashCollection.setStatus(1234560); |
|
|
|
} |
|
|
|
cashCollection.setSubmitterId(cashCollection.getSubmitterId()); |
|
|
|
cashCollection.setReceivedMarket(null); |
|
|
|
} |
|
|
|
cashCollection.setMarkets(markets); |
|
|
|
// cashCollection.setMarkets(markets); |
|
|
|
PageHelper.startPage(pageNum, pageSize); |
|
|
|
List<CashCollection> cashCollections = cashCollectionMapper.selectCollection1(pageNum, pageSize, cashCollection); |
|
|
|
return new PageInfo<>(cashCollections); |
|
|
|
} |
|
|
|
|
|
|
|
//补全手续费等内容 |
|
|
|
@Override |
|
|
|
public String complete(CashRecord cashRecord) { |
|
|
|
@ -239,6 +306,7 @@ public class CashCollectionServiceImpl implements CashCollectionService { |
|
|
|
|
|
|
|
return rows > 0 ? "编辑成功" : "编辑失败"; |
|
|
|
} |
|
|
|
|
|
|
|
//根据精网号查询姓名和地区 |
|
|
|
@Override |
|
|
|
public User getNameAndMarket(Integer jwcode) { |
|
|
|
@ -249,12 +317,14 @@ public class CashCollectionServiceImpl implements CashCollectionService { |
|
|
|
|
|
|
|
return user; |
|
|
|
} |
|
|
|
|
|
|
|
//获取收款活动列表 |
|
|
|
@Override |
|
|
|
public List<RechargeActivity> getActivityList() { |
|
|
|
LocalDateTime now = LocalDateTime.now(); |
|
|
|
return cashCollectionMapper.getActivityList(now); |
|
|
|
} |
|
|
|
|
|
|
|
//同步g_order订单到cash_record表 |
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
@ -312,11 +382,13 @@ public class CashCollectionServiceImpl implements CashCollectionService { |
|
|
|
//存入现金库 |
|
|
|
cashCollectionMapper.add(cashRecord); |
|
|
|
cashCollectionMapper.markSynced(gOrder.getId()); |
|
|
|
}log.info("同步完成一批,数量 {}", gOrders.size()); |
|
|
|
} |
|
|
|
log.info("同步完成一批,数量 {}", gOrders.size()); |
|
|
|
if (gOrders.size() < 100) { |
|
|
|
break; // 最后一批 |
|
|
|
} |
|
|
|
}return "同步完毕"; |
|
|
|
} |
|
|
|
return "同步完毕"; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
|