Commit 2867e4ef by huluobin

Merge branch 'master' into 3.8

parents 785eb06d 15d67332
......@@ -132,7 +132,12 @@ public class OrderManageServiceImpl extends ServiceImpl<OrderManageMapper, Order
@Override
public void updateOrderManage(OrderManage param) {
OrderManage orderManage = orderManageMapper.selectById(param.getId());
if (!orderManage.getStatus().equals(OrderManage.STATUS_SYSTEM_UN_CHECK)) {
throw new RRException("非待核算状态不能修改订单");
}
List<OrderServe> orderServeList = orderServeMapper.selectList(new LambdaQueryWrapper<OrderServe>().eq(OrderServe::getOrderId, param.getId()));
ScheduleManage scheduleManage = scheduleManageMapper.selectById(orderManage.getScheduledId());
......@@ -408,11 +413,6 @@ public class OrderManageServiceImpl extends ServiceImpl<OrderManageMapper, Order
if (StringUtils.isNotEmpty(param.getCustomerPhone())) {
wrapper.like(OrderManage::getTelephone, param.getCustomerPhone());
}
if (param.getCustomerId() != null) {
wrapper.and(wrapper2 -> wrapper.eq(OrderManage::getOrderUser, param.getCustomerId())
.or(wrapper3 -> wrapper3.eq(OrderManage::getPayUser, param.getCustomerId())));
}
if (param.getDepartmentId() != null) {
wrapper.eq(OrderManage::getDepartmentId, param.getDepartmentId());
}
......@@ -423,7 +423,11 @@ public class OrderManageServiceImpl extends ServiceImpl<OrderManageMapper, Order
wrapper.ne(OrderManage::getStatus, OrderManage.STATUS_SYSTEM_UN_CHECK);
}
wrapper.ne(OrderManage::getStatus, OrderManage.STATUS_DELETED);
if (param.getCustomerId() != null) {
wrapper.and(wrapper2 -> wrapper.eq(OrderManage::getOrderUser, param.getCustomerId())
.or()
.eq(OrderManage::getPayUser, param.getCustomerId()));
}
//noinspection unchecked
wrapper.orderByDesc(OrderManage::getCreateTime);
......
......@@ -66,6 +66,9 @@ public class PayServiceImpl implements PayService {
throw new RRException("订单状态异常");
}
this.checkCustomerBalance(currentCustomerId, orderId);
/*1、扣除余额*/
ConsumerCommand consumerCmd = ConsumerCommand.builder()
.amount(orderManage.getTotalPaymentAmount().multiply(new BigDecimal(100)).intValue())
......@@ -136,6 +139,22 @@ public class PayServiceImpl implements PayService {
}
private void checkCustomerBalance(Integer customerId, Integer orderId) throws RRException {
OrderManage orderManage = orderManageService.getById(orderId);
CustomerBalance customerBalance = customerBalanceMapper.selectOne(new LambdaQueryWrapper<CustomerBalance>().eq(CustomerBalance::getCustomerId, customerId));
if (customerBalance == null) {
throw new RRException("您不是会员,请直接使用pos支付");
}
if (orderManage.getTotalPaymentAmount().multiply(new BigDecimal(100)).intValue() < customerBalance.getBalance()) {
throw new RRException("请使用余额支付");
}
if (customerBalance.getBalance() <= 0) {
throw new RRException("余额为0,请直接使用pos支付");
}
}
@Override
public WxPayMpOrderResult balanceWxPay(BalanceWxPayQuery qry) throws UnknownHostException, WxPayException {
......@@ -146,15 +165,9 @@ public class PayServiceImpl implements PayService {
}
//2、余额检查
CustomerBalance customerBalance = customerBalanceMapper.selectOne(new LambdaQueryWrapper<CustomerBalance>().eq(CustomerBalance::getCustomerId, orderManage.getOrderUser()));
if (customerBalance == null) {
throw new RRException("余额不存在");
}
this.checkCustomerBalance(qry.getCustomerId(), qry.getOrderId());
CustomerBalance customerBalance = customerBalanceMapper.selectOne(new LambdaQueryWrapper<CustomerBalance>().eq(CustomerBalance::getCustomerId, qry.getCustomerId()));
if (orderManage.getTotalPaymentAmount().multiply(new BigDecimal(100)).intValue() < customerBalance.getBalance()) {
throw new RRException("请使用余额支付");
}
//3、微信统一下单
BigDecimal leftTotalPaymentAmount = orderManage.getTotalPaymentAmount().subtract(new BigDecimal(customerBalance.getBalance()).divide(new BigDecimal(100), 2, BigDecimal.ROUND_HALF_UP));
......@@ -193,12 +206,8 @@ public class PayServiceImpl implements PayService {
throw new RRException("订单状态异常");
}
//2、余额检查
CustomerBalance customerBalance = customerBalanceMapper.selectOne(new LambdaQueryWrapper<CustomerBalance>().eq(CustomerBalance::getCustomerId, currentCustomerId));
if (orderManage.getTotalPaymentAmount().multiply(new BigDecimal(100)).intValue() < customerBalance.getBalance()) {
throw new RRException("请使用余额支付");
}
this.checkCustomerBalance(currentCustomerId, orderId);
//3、更新订单
//支付类型:请余额pos支付
......
......@@ -894,6 +894,10 @@ public class ScheduleManageServiceImpl extends ServiceImpl<ScheduleManageMapper,
log.info("更新预约:{}", cmd);
ScheduleManage scheduleManage = this.setScheduleServe(cmd.getScheduleManageDTO(), cmd.getDefaultNodeList());
if (scheduleManage.getStatus().equals(ScheduleManage.STATUS_KEEP_SCHEDULED)) {
throw new RRException("已完成预约,不能修改");
}
if (SessionUtils.isSourceFromCustomer()) {
this.validSubmit(scheduleManage);
}
......@@ -905,13 +909,21 @@ public class ScheduleManageServiceImpl extends ServiceImpl<ScheduleManageMapper,
List<ScheduleServe> scheduleServeList = scheduleManage.getScheduleServeList();
scheduleServeList.forEach(scheduleServe -> scheduleServe.setSchId(scheduleManage.getId()));
scheduleServeList.forEach(scheduleServe -> {
if (scheduleServe.getId() != null) {
scheduleServeMapper.updateById(scheduleServe);
} else {
scheduleServeMapper.insert(scheduleServe);
}
});
List<ScheduleServe> insertScheduleServeList = scheduleServeList.stream()
.filter(scheduleServe -> scheduleServe.getId() == null).collect(Collectors.toList());
List<ScheduleServe> updateScheduleServeList = scheduleServeList.stream().filter(scheduleServe -> scheduleServe.getId() != null).collect(Collectors.toList());
insertScheduleServeList.forEach(scheduleServeMapper::insert);
updateScheduleServeList.forEach(scheduleServeMapper::updateById);
// //数据库死锁
// scheduleServeList.forEach(scheduleServe -> {
// if (scheduleServe.getId() != null) {
// scheduleServeMapper.updateById(scheduleServe);
// } else {
// scheduleServeMapper.insert(scheduleServe);
// }
// });
List<Integer> removeIds = oldScheduleServeIds.stream().filter(id -> !scheduleServeList.stream().map(ScheduleServe::getId).collect(Collectors.toList()).contains(id)).collect(Collectors.toList());
if (ListUtil.isNotEmpty(removeIds)) {
scheduleServeMapper.deleteBatchIds(removeIds);
......@@ -919,7 +931,9 @@ public class ScheduleManageServiceImpl extends ServiceImpl<ScheduleManageMapper,
scheduleManage.addScheduleServeList(scheduleServeList);
this.createOrder(scheduleManage);
technicianPushService.updateScheduledMsg(scheduleManage.getId());
if (SessionUtils.getSourceFrom().equals("customer")) {
technicianPushService.updateScheduledMsg(scheduleManage.getId());
}
}
@Override
......
......@@ -34,6 +34,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;
import java.security.InvalidParameterException;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
......@@ -230,7 +231,16 @@ public class OrderManageController {
@PostMapping("/technician/ordermanage/updateOrderManage")
public JsonResult<Void> updateOrderManage(@RequestHeader String token,
@RequestBody OrderManage param) {
orderManageService.updateOrderManage(param);
OrderIdLock orderIdLock = OrderIdLock.getInstance();
if (param.getId() == null) {
throw new InvalidParameterException();
}
try {
orderIdLock.lock(param.getId());
orderManageService.updateOrderManage(param);
} finally {
orderIdLock.unlock(param.getId());
}
return JsonResult.success();
}
......@@ -269,4 +279,4 @@ public class OrderManageController {
// marketService.calcOrderAmount(orderId);
return JsonResult.success();
}
}
\ No newline at end of file
}
......@@ -5,12 +5,14 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gogirl.application.market.discount.IVipServeService;
import com.gogirl.application.order.serve.ScheduleManageService;
import com.gogirl.application.order.serve.ScheduleServeService;
import com.gogirl.application.user.customer.CustomerBalanceService;
import com.gogirl.application.xcx.GogirlTokenService;
import com.gogirl.assembler.PurchaseSkuDTOAssembler;
import com.gogirl.assembler.ScheduleManageDTOAssembler;
import com.gogirl.domain.market.discount.VipServe;
import com.gogirl.domain.order.serve.ScheduleManage;
import com.gogirl.domain.order.serve.ScheduleServe;
import com.gogirl.domain.product.serve.BaseProduce;
import com.gogirl.domain.store.store.StoreTechnician;
import com.gogirl.domain.xcx.GogirlToken;
......@@ -21,7 +23,6 @@ import com.gogirl.infrastructure.mapper.product.purchase.PurchaseSkuMapper;
import com.gogirl.infrastructure.mapper.product.serve.BaseProduceMapper;
import com.gogirl.infrastructure.util.SessionUtils;
import com.gogirl.infrastructure.util.lock.CustomerIdLock;
import com.gogirl.infrastructure.util.lock.ScheduleServeIdLock;
import com.gogirl.infrastructure.util.lock.ScheduledLock;
import com.gogirl.shared.order.*;
import com.gogirl.shared.product.LeisureScheduleServeQuery;
......@@ -36,6 +37,7 @@ import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import java.security.InvalidParameterException;
import java.text.ParseException;
import java.util.List;
import java.util.Map;
......@@ -49,6 +51,7 @@ import java.util.stream.Collectors;
@Slf4j
public class ScheduleManageController {
private final ScheduleServeService scheduleServeService;
private final ScheduleManageService scheduleManageService;
private final GogirlTokenService gogirlTokenService;
private final CustomerBalanceService customerBalanceService;
......@@ -211,8 +214,22 @@ public class ScheduleManageController {
@ApiOperation("更新预约")
@PostMapping("/technician/schedule/updateSchedule")
public JsonResult<Void> updateSchedule(@RequestBody SubmitScheduleCommand cmd) throws ParseException, ExecutionException, InterruptedException {
cmd.getScheduleManageDTO().setDepartmentId(SessionUtils.getTechnicianToken().getDepartmentId());
scheduleManageService.updateSchedule(cmd);
ScheduledLock scheduledLock = ScheduledLock.getInstance();
try {
log.info("店员更新预约:{}", cmd);
if (cmd.getScheduleManageDTO().getId() == null) {
throw new InvalidParameterException();
}
scheduledLock.lock(cmd.getScheduleManageDTO().getId());
cmd.getScheduleManageDTO().setDepartmentId(SessionUtils.getTechnicianToken().getDepartmentId());
scheduleManageService.updateSchedule(cmd);
} finally {
scheduledLock.unlock(cmd.getScheduleManageDTO().getId());
}
return JsonResult.success();
}
......@@ -231,12 +248,17 @@ public class ScheduleManageController {
@RequestParam Integer scheduleServeId,
@RequestParam Integer status,
@RequestParam Integer forceLeisureConfig) {
ScheduleServeIdLock lock = ScheduleServeIdLock.getInstance();
ScheduleServe scheduleServe = scheduleServeService.getById(scheduleServeId);
if (scheduleServe.getSchId() == null) {
throw new InvalidParameterException();
}
int scheduleId = scheduleServe.getSchId();
ScheduledLock lock = ScheduledLock.getInstance();
try {
lock.lock(scheduleServeId);
lock.lock(scheduleId);
scheduleManageService.updateScheduledServeStatus(scheduleServeId, status, forceLeisureConfig);
} finally {
lock.unlock(scheduleServeId);
lock.unlock(scheduleId);
}
return JsonResult.success();
}
......
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