Commit 824e3510 authored by shiyu's avatar shiyu

交换单系统自动完成

parent e904f89f
...@@ -4,10 +4,12 @@ import com.github.pagehelper.PageInfo; ...@@ -4,10 +4,12 @@ import com.github.pagehelper.PageInfo;
import com.wwdz.ch.admin.entity.vo.SysExchangeApplyOrderDetailVo; import com.wwdz.ch.admin.entity.vo.SysExchangeApplyOrderDetailVo;
import com.wwdz.ch.admin.entity.vo.SysExchangeOrderVo; import com.wwdz.ch.admin.entity.vo.SysExchangeOrderVo;
import com.wwdz.ch.admin.service.SysExchangeApplyOrderService; import com.wwdz.ch.admin.service.SysExchangeApplyOrderService;
import com.wwdz.ch.core.api.WxAppletApi;
import com.wwdz.ch.core.consts.DistributionEnum; import com.wwdz.ch.core.consts.DistributionEnum;
import com.wwdz.ch.core.consts.ExchangeApplyOrderEnum; import com.wwdz.ch.core.consts.ExchangeApplyOrderEnum;
import com.wwdz.ch.core.entity.SupplierItemVo; import com.wwdz.ch.core.entity.SupplierItemVo;
import com.wwdz.ch.core.entity.exchange.ExchangeApplyOrderVo; import com.wwdz.ch.core.entity.exchange.ExchangeApplyOrderVo;
import com.wwdz.ch.core.notify.AliSmsSender;
import com.wwdz.ch.core.type.PageSearchResult; import com.wwdz.ch.core.type.PageSearchResult;
import com.wwdz.ch.core.type.Result; import com.wwdz.ch.core.type.Result;
import com.wwdz.ch.core.util.CacheUtil; import com.wwdz.ch.core.util.CacheUtil;
...@@ -61,11 +63,18 @@ public class SysExchangeApplyOrderServiceImpl implements SysExchangeApplyOrderSe ...@@ -61,11 +63,18 @@ public class SysExchangeApplyOrderServiceImpl implements SysExchangeApplyOrderSe
@Autowired @Autowired
DistributionOrderDao distributionOrderDao; DistributionOrderDao distributionOrderDao;
@Autowired
AliSmsSender aliSmsSender;
@Autowired
WxAppletApi wxAppletApi;
@Transactional @Transactional
@Override @Override
public Result handleApplyOrder(ExchangeApplyOrderRequestDto dto) { public Result handleApplyOrder(ExchangeApplyOrderRequestDto dto) {
try { try {
//短信内容
String orderId = dto.getExchangeApplyOrderId(); String orderId = dto.getExchangeApplyOrderId();
ExchangeApplyOrder exchangeApplyOrder = exchangeApplyOrderDao.findByOrderId(orderId); ExchangeApplyOrder exchangeApplyOrder = exchangeApplyOrderDao.findByOrderId(orderId);
String targetUserOrderId = exchangeApplyOrder.getTargetUserOrderId(); String targetUserOrderId = exchangeApplyOrder.getTargetUserOrderId();
...@@ -76,6 +85,22 @@ public class SysExchangeApplyOrderServiceImpl implements SysExchangeApplyOrderSe ...@@ -76,6 +85,22 @@ public class SysExchangeApplyOrderServiceImpl implements SysExchangeApplyOrderSe
//订单更新为待发货 //订单更新为待发货
distributionOrderDao.updateState(targetUserOrderId, DistributionEnum.DistributionOrderStateEnum.PRE_SEND.getCode()); distributionOrderDao.updateState(targetUserOrderId, DistributionEnum.DistributionOrderStateEnum.PRE_SEND.getCode());
distributionOrderDao.updateState(userOrderId, DistributionEnum.DistributionOrderStateEnum.PRE_SEND.getCode()); distributionOrderDao.updateState(userOrderId, DistributionEnum.DistributionOrderStateEnum.PRE_SEND.getCode());
//发短信通知申请单双方,平台的鉴定结果
try {
//通知提交方
String commitUrl = wxAppletApi.getUrlLink("/pages/saleExchangeApplyOrderDetail/index?orderId=" + userOrderId,null);
String commitMsg = "您的换藏商品平台检查通过,会在48小时内发出,请前往" + commitUrl + "查看";
aliSmsSender.sendSms(exchangeApplyOrder.getUserOrderId(), commitMsg);
//通知受理方
String receiveUrl = wxAppletApi.getUrlLink("/pages/saleExchangeApplyOrderDetail/index?orderId=" + targetUserOrderId,null);
String receiveMsg = "您的换藏商品平台检查通过,会在48小时内发出,请前往" + receiveUrl + "查看";
aliSmsSender.sendSms(exchangeApplyOrder.getUserOrderId(), receiveMsg);
logger.info(">>>>>>>>> 交换申请单号:{}, 通过, 发送平台检查结果通知短信成功 <<<<<<<<<", exchangeApplyOrder.getExchangeApplyOrderId());
} catch (Exception e) {
logger.info(">>>>>>>>> 交换申请单号:{}, 通过, 发送平台检查结果通知短信失败 <<<<<<<<<", exchangeApplyOrder.getExchangeApplyOrderId());
}
} else { } else {
//平台审核不通过 //平台审核不通过
exchangeApplyOrderDao.updateState(orderId, dto.getState()); exchangeApplyOrderDao.updateState(orderId, dto.getState());
...@@ -110,7 +135,22 @@ public class SysExchangeApplyOrderServiceImpl implements SysExchangeApplyOrderSe ...@@ -110,7 +135,22 @@ public class SysExchangeApplyOrderServiceImpl implements SysExchangeApplyOrderSe
targetOrderSnapshot.setDistributionOrderId(targetUserOrderId); targetOrderSnapshot.setDistributionOrderId(targetUserOrderId);
targetOrderSnapshot.setIsValid(false); targetOrderSnapshot.setIsValid(false);
exchangeOrderSnapshotDao.update(targetOrderSnapshot); exchangeOrderSnapshotDao.update(targetOrderSnapshot);
//发短信通知申请单双方,平台的鉴定结果
try {
//通知提交方
String commitUrl = wxAppletApi.getUrlLink("/pages/saleExchangeApplyOrderDetail/index?orderId=" + userOrderId,null);
String commitMsg = "您的换藏商品平台检查不通过,订单已被取消,请前往" + commitUrl + "查看";
aliSmsSender.sendSms(exchangeApplyOrder.getUserOrderId(), commitMsg);
//通知受理方
String receiveUrl = wxAppletApi.getUrlLink("/pages/saleExchangeApplyOrderDetail/index?orderId=" + targetUserOrderId,null);
String receiveMsg = "您的换藏商品平台检查不通过,订单已被取消,请前往" + receiveUrl + "查看";
aliSmsSender.sendSms(exchangeApplyOrder.getUserOrderId(), receiveMsg);
logger.info(">>>>>>>>> 交换申请单号:{}, 不通过, 发送平台检查结果通知短信成功 <<<<<<<<<", exchangeApplyOrder.getExchangeApplyOrderId());
} catch (Exception e) {
logger.info(">>>>>>>>> 交换申请单号:{}, 不通过, 发送平台检查结果通知短信失败 <<<<<<<<<", exchangeApplyOrder.getExchangeApplyOrderId());
}
} }
return Result.success(); return Result.success();
} catch (Exception e) { } catch (Exception e) {
logger.error("平台处理换物申请单 error:{}", e); logger.error("平台处理换物申请单 error:{}", e);
......
...@@ -5,6 +5,7 @@ import com.wwdz.ch.admin.service.SysUserBillService; ...@@ -5,6 +5,7 @@ import com.wwdz.ch.admin.service.SysUserBillService;
import com.wwdz.ch.core.api.LogisticsApi; import com.wwdz.ch.core.api.LogisticsApi;
import com.wwdz.ch.core.consts.BillEnum; import com.wwdz.ch.core.consts.BillEnum;
import com.wwdz.ch.core.consts.DistributionEnum; import com.wwdz.ch.core.consts.DistributionEnum;
import com.wwdz.ch.core.consts.ExchangeApplyOrderEnum;
import com.wwdz.ch.core.consts.LogisticsStateEnum; import com.wwdz.ch.core.consts.LogisticsStateEnum;
import com.wwdz.ch.core.entity.LogisticsInfo; import com.wwdz.ch.core.entity.LogisticsInfo;
import com.wwdz.ch.core.entity.LogisticsRequestDto; import com.wwdz.ch.core.entity.LogisticsRequestDto;
...@@ -13,8 +14,10 @@ import com.wwdz.ch.core.type.Result; ...@@ -13,8 +14,10 @@ import com.wwdz.ch.core.type.Result;
import com.wwdz.ch.db.dao.distribution.DistributionOrderDao; import com.wwdz.ch.db.dao.distribution.DistributionOrderDao;
import com.wwdz.ch.db.dao.distribution.UserAccountDetailDao; import com.wwdz.ch.db.dao.distribution.UserAccountDetailDao;
import com.wwdz.ch.db.dao.distribution.UserBillDao; import com.wwdz.ch.db.dao.distribution.UserBillDao;
import com.wwdz.ch.db.dao.exchange.ExchangeApplyOrderDao;
import com.wwdz.ch.db.domain.User; import com.wwdz.ch.db.domain.User;
import com.wwdz.ch.db.domain.distribution.DistributionOrder; import com.wwdz.ch.db.domain.distribution.DistributionOrder;
import com.wwdz.ch.db.domain.distribution.ExchangeApplyOrder;
import com.wwdz.ch.db.domain.distribution.SpecialPerformance; import com.wwdz.ch.db.domain.distribution.SpecialPerformance;
import com.wwdz.ch.db.domain.distribution.UserBill; import com.wwdz.ch.db.domain.distribution.UserBill;
import com.wwdz.ch.db.dto.request.UserRequestDto; import com.wwdz.ch.db.dto.request.UserRequestDto;
...@@ -63,6 +66,9 @@ public class RefreshLogisticsJob { ...@@ -63,6 +66,9 @@ public class RefreshLogisticsJob {
@Autowired @Autowired
SysUserBillService sysUserBillService; SysUserBillService sysUserBillService;
@Autowired
ExchangeApplyOrderDao exchangeApplyOrderDao;
/** /**
* 隔4小时运行一次 * 隔4小时运行一次
*/ */
...@@ -160,12 +166,18 @@ public class RefreshLogisticsJob { ...@@ -160,12 +166,18 @@ public class RefreshLogisticsJob {
for (DistributionOrder distributionOrder : distributionOrderList) { for (DistributionOrder distributionOrder : distributionOrderList) {
try { try {
distributionOrderDao.updateState(distributionOrder.getDistributionOrderId(), DistributionEnum.DistributionOrderStateEnum.FINISH.getCode()); distributionOrderDao.updateState(distributionOrder.getDistributionOrderId(), DistributionEnum.DistributionOrderStateEnum.FINISH.getCode());
//关联的订单账单,用户账户的待入账金额改为已入账 //换藏订单在完成后,要把交换申请单状态改成已完成
userAccountDetailDao.updateState(distributionOrder.getDistributionOrderId(), BillEnum.AccountDetailStateEnum.ENTRY.getCode()); if (distributionOrder.getType() == DistributionEnum.DistributionTypeEnum.EXCHANGE.getCode()) {
//调整用户的月度账单 ExchangeApplyOrder exchangeApplyOrder = exchangeApplyOrderDao.findByExchangeOrderId(distributionOrder.getDistributionOrderId());
Result result = sysUserBillService.finishCalculate(distributionOrder); exchangeApplyOrderDao.updateState(exchangeApplyOrder.getExchangeApplyOrderId(), ExchangeApplyOrderEnum.StateEnum.FINISH.getCode());
if (!result.getSuccess()) { } else {
throw new Exception("调整用户的月度账单error"); //关联的订单账单,用户账户的待入账金额改为已入账
userAccountDetailDao.updateState(distributionOrder.getDistributionOrderId(), BillEnum.AccountDetailStateEnum.ENTRY.getCode());
//调整用户的月度账单
Result result = sysUserBillService.finishCalculate(distributionOrder);
if (!result.getSuccess()) {
throw new Exception("调整用户的月度账单error");
}
} }
} catch (Exception e) { } catch (Exception e) {
logger.error("订单自动完成,更新账单失败:{}", e); logger.error("订单自动完成,更新账单失败:{}", e);
......
...@@ -34,7 +34,7 @@ public class ExchangeApplyOrderDaoImpl implements ExchangeApplyOrderDao { ...@@ -34,7 +34,7 @@ public class ExchangeApplyOrderDaoImpl implements ExchangeApplyOrderDao {
JdbcHelper.ifPresent(dto.getUserId(), criteria::andUserIdEqualTo); JdbcHelper.ifPresent(dto.getUserId(), criteria::andUserIdEqualTo);
JdbcHelper.ifPresent(dto.getTargetUserId(), criteria::andTargetUserIdEqualTo); JdbcHelper.ifPresent(dto.getTargetUserId(), criteria::andTargetUserIdEqualTo);
JdbcHelper.ifPresent(dto.getState(), criteria::andStateEqualTo); JdbcHelper.ifPresent(dto.getState(), criteria::andStateEqualTo);
example.setOrderByClause(" update_time desc"); example.setOrderByClause(" create_time desc");
PageHelper.startPage(dto.getPage(), dto.getLimit()); PageHelper.startPage(dto.getPage(), dto.getLimit());
return exchangeApplyOrderMapper.selectByExample(example); return exchangeApplyOrderMapper.selectByExample(example);
} }
......
...@@ -168,9 +168,8 @@ public class ExchangeApplyOrderServiceImpl implements ExchangeApplyOrderService ...@@ -168,9 +168,8 @@ public class ExchangeApplyOrderServiceImpl implements ExchangeApplyOrderService
Result commitExchangeOrderResult = exchangeService.exchange(commitExchangeDto); Result commitExchangeOrderResult = exchangeService.exchange(commitExchangeDto);
if (!commitExchangeOrderResult.getSuccess()) { if (!commitExchangeOrderResult.getSuccess()) {
logger.error(">>>>>>> 创建申请方交换订单失败:{} <<<<<<<", commitExchangeOrderResult.getErrmsg()); logger.error(">>>>>>> 创建申请方交换订单失败:{} <<<<<<<", commitExchangeOrderResult.getErrmsg());
throw new Exception("创建申请方交换订单失败"); throw new Exception(commitExchangeOrderResult.getErrmsg());
} }
//为受理方创建订单 //为受理方创建订单
ExchangeRequestDto receiveExchangeDto = new ExchangeRequestDto(); ExchangeRequestDto receiveExchangeDto = new ExchangeRequestDto();
receiveExchangeDto.setIsMultiple(true); receiveExchangeDto.setIsMultiple(true);
...@@ -201,7 +200,7 @@ public class ExchangeApplyOrderServiceImpl implements ExchangeApplyOrderService ...@@ -201,7 +200,7 @@ public class ExchangeApplyOrderServiceImpl implements ExchangeApplyOrderService
Result receiveExchangeOrderResult = exchangeService.exchange(receiveExchangeDto); Result receiveExchangeOrderResult = exchangeService.exchange(receiveExchangeDto);
if (!receiveExchangeOrderResult.getSuccess()) { if (!receiveExchangeOrderResult.getSuccess()) {
logger.error(">>>>>>>> 创建接收方方交换订单失败:{} <<<<<<<<", receiveExchangeOrderResult.getErrmsg()); logger.error(">>>>>>>> 创建接收方方交换订单失败:{} <<<<<<<<", receiveExchangeOrderResult.getErrmsg());
throw new Exception("创建接收方方交换订单失败"); throw new Exception(receiveExchangeOrderResult.getErrmsg());
} }
ExchangeApplyOrder updateExchangeApplyOrder = new ExchangeApplyOrder(); ExchangeApplyOrder updateExchangeApplyOrder = new ExchangeApplyOrder();
updateExchangeApplyOrder.setExchangeApplyOrderId(orderId); updateExchangeApplyOrder.setExchangeApplyOrderId(orderId);
...@@ -223,20 +222,18 @@ public class ExchangeApplyOrderServiceImpl implements ExchangeApplyOrderService ...@@ -223,20 +222,18 @@ public class ExchangeApplyOrderServiceImpl implements ExchangeApplyOrderService
url = wxAppletApi.getUrlLink("/pages/saleExchangeApplyOrderDetail/index?orderId=" + orderId,null); url = wxAppletApi.getUrlLink("/pages/saleExchangeApplyOrderDetail/index?orderId=" + orderId,null);
msg = "您申请的换货申请单被拒绝," + "请前往"+ url + "查看"; msg = "您申请的换货申请单被拒绝," + "请前往"+ url + "查看";
} }
//发短信通知申请方 //发短信通知申请方
try { try {
aliSmsSender.sendSms(dto.getTargetUserId(), msg); aliSmsSender.sendSms(dto.getTargetUserId(), msg);
} catch (Exception e) { } catch (Exception e) {
logger.info(">>>>>>>>> 用户id:{}, 发送换货申请结果通知短信失败 <<<<<<<<<", dto.getTargetUserId()); logger.info(">>>>>>>>> 用户id:{}, 发送换货申请结果通知短信失败 <<<<<<<<<", dto.getTargetUserId());
} }
return Result.success(); return Result.success();
} catch (Exception e) { } catch (Exception e) {
logger.error("处理换物申请单 error:{}", e); logger.error("处理换物申请单 error:{}", e);
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
return Result.failed();
} }
return Result.failed();
} }
@Override @Override
......
...@@ -68,7 +68,7 @@ public class ExchangeOrderServiceImpl implements ExchangeOrderService { ...@@ -68,7 +68,7 @@ public class ExchangeOrderServiceImpl implements ExchangeOrderService {
try { try {
//检查是否有超时未支付订单 //检查是否有超时未支付订单
dto.setBuyerId(dto.getUserId()); dto.setBuyerId(dto.getUserId());
checkPrePayTimeOut(dto.getUserId(), null); checkPrePayTimeOut(dto.getUserId());
if (StringUtils.hasLength(dto.getSearchParam())) { if (StringUtils.hasLength(dto.getSearchParam())) {
//判断查询条件是否为中文,是的话就根据商品名称模糊查询 //判断查询条件是否为中文,是的话就根据商品名称模糊查询
if (RegexUtil.isContainChinese(dto.getSearchParam())) { if (RegexUtil.isContainChinese(dto.getSearchParam())) {
...@@ -162,9 +162,9 @@ public class ExchangeOrderServiceImpl implements ExchangeOrderService { ...@@ -162,9 +162,9 @@ public class ExchangeOrderServiceImpl implements ExchangeOrderService {
@Override @Override
public Result findOrderDetail(DistributionOrderRequestDto dto) { public Result findOrderDetail(DistributionOrderRequestDto dto) {
try { try {
//检查是否有超时未寄出的
checkPrePayTimeOut(dto.getUserId(), null);
dto.setBuyerId(dto.getUserId()); dto.setBuyerId(dto.getUserId());
//检查是否有超时未寄出的
checkPrePayTimeOut(dto.getUserId());
DistributionOrder distributionOrder = distributionOrderDao.findById(dto.getDistributionOrderId()); DistributionOrder distributionOrder = distributionOrderDao.findById(dto.getDistributionOrderId());
//用户交换得到的商品信息 //用户交换得到的商品信息
List<SupplierItemVo> targetItemList = new ArrayList<>(); List<SupplierItemVo> targetItemList = new ArrayList<>();
...@@ -259,12 +259,10 @@ public class ExchangeOrderServiceImpl implements ExchangeOrderService { ...@@ -259,12 +259,10 @@ public class ExchangeOrderServiceImpl implements ExchangeOrderService {
/** /**
* 检查用户订单是否有超时未寄出 * 检查用户订单是否有超时未寄出
* @param userId * @param userId
* @param distributorId
*/ */
private void checkPrePayTimeOut(Long userId, Long distributorId){ private void checkPrePayTimeOut(Long userId){
DistributionOrderRequestDto dto = new DistributionOrderRequestDto(); DistributionOrderRequestDto dto = new DistributionOrderRequestDto();
dto.setBuyerId(userId); dto.setBuyerId(userId);
dto.setSellerId(distributorId);
dto.setType(DistributionEnum.DistributionTypeEnum.EXCHANGE.getCode()); dto.setType(DistributionEnum.DistributionTypeEnum.EXCHANGE.getCode());
dto.setState(DistributionEnum.DistributionOrderStateEnum.PRE_EXCHANGE.getCode()); dto.setState(DistributionEnum.DistributionOrderStateEnum.PRE_EXCHANGE.getCode());
List<DistributionOrder> prePayList = distributionOrderDao.findByPage(dto); List<DistributionOrder> prePayList = distributionOrderDao.findByPage(dto);
...@@ -274,7 +272,6 @@ public class ExchangeOrderServiceImpl implements ExchangeOrderService { ...@@ -274,7 +272,6 @@ public class ExchangeOrderServiceImpl implements ExchangeOrderService {
//超出48小时未寄出,订单取消 //超出48小时未寄出,订单取消
long diffInHours = diffInMillies / (60 * 1000 * 60); long diffInHours = diffInMillies / (60 * 1000 * 60);
if (diffInHours >= 48) { if (diffInHours >= 48) {
distributionOrderDao.updateState(distributionOrder.getDistributionOrderId(), DistributionEnum.DistributionOrderStateEnum.CANCEL.getCode());
//换藏的品取消订单后恢复库存 //换藏的品取消订单后恢复库存
ExchangeApplyOrder exchangeApplyOrder = exchangeApplyOrderDao.findByExchangeOrderId(orderId); ExchangeApplyOrder exchangeApplyOrder = exchangeApplyOrderDao.findByExchangeOrderId(orderId);
exchangeApplyOrderDao.updateState(exchangeApplyOrder.getExchangeApplyOrderId(), ExchangeApplyOrderEnum.StateEnum.SYSTEM_CANCEL.getCode()); exchangeApplyOrderDao.updateState(exchangeApplyOrder.getExchangeApplyOrderId(), ExchangeApplyOrderEnum.StateEnum.SYSTEM_CANCEL.getCode());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment