|
|
@@ -0,0 +1,189 @@
|
|
|
+package org.dromara.order.service.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
+import org.dromara.api.RemoteCustomerService;
|
|
|
+import org.dromara.api.RemotePetService;
|
|
|
+import org.dromara.api.domain.vo.RemoteCustomerVo;
|
|
|
+import org.dromara.api.domain.vo.RemotePetVo;
|
|
|
+import org.dromara.common.core.exception.ServiceException;
|
|
|
+import org.dromara.common.mybatis.core.page.PageQuery;
|
|
|
+import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
|
+import org.dromara.common.mybatis.utils.WrapperUtils;
|
|
|
+import org.dromara.common.satoken.utils.LoginHelper;
|
|
|
+import org.dromara.fulfiller.api.RemoteFulfillerService;
|
|
|
+import org.dromara.fulfiller.api.domain.vo.RemoteFulfillerVo;
|
|
|
+import org.dromara.fulfiller.api.model.FulfillerLoginUser;
|
|
|
+import org.dromara.order.domain.SysOrder;
|
|
|
+import org.dromara.order.domain.SysSubOrder;
|
|
|
+import org.dromara.order.domain.SysSubOrderLog;
|
|
|
+import org.dromara.order.domain.bo.SysSubOrderCancelBo;
|
|
|
+import org.dromara.order.domain.bo.SysSubOrderDispatchBo;
|
|
|
+import org.dromara.order.domain.bo.SysSubOrderListPageBo;
|
|
|
+import org.dromara.order.domain.vo.SysSubOrderListPageVo;
|
|
|
+import org.dromara.order.domain.vo.SysSubOrderVo;
|
|
|
+import org.dromara.order.enums.OrderLogActionTypeEnum;
|
|
|
+import org.dromara.order.enums.OrderLogActionerTypeEnum;
|
|
|
+import org.dromara.order.enums.OrderLogTypeEnum;
|
|
|
+import org.dromara.order.enums.OrderStatusEnum;
|
|
|
+import org.dromara.order.mapper.SysOrderMapper;
|
|
|
+import org.dromara.order.mapper.SysSubOrderLogMapper;
|
|
|
+import org.dromara.order.mapper.SysSubOrderMapper;
|
|
|
+import org.dromara.order.service.ISysSubOrderService;
|
|
|
+import org.dromara.system.api.RemoteStoreService;
|
|
|
+import org.dromara.system.api.RemoteUserService;
|
|
|
+import org.dromara.system.api.domain.vo.RemoteStoreVo;
|
|
|
+import org.dromara.system.api.domain.vo.RemoteUserVo;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+@Service
|
|
|
+@RequiredArgsConstructor
|
|
|
+public class SysSubOrderServiceImpl implements ISysSubOrderService {
|
|
|
+
|
|
|
+ private final SysSubOrderMapper baseMapper;
|
|
|
+ private final SysSubOrderLogMapper subOrderLogMapper;
|
|
|
+
|
|
|
+ @DubboReference
|
|
|
+ private final RemoteUserService remoteUserService;
|
|
|
+ @DubboReference
|
|
|
+ private final RemoteCustomerService remoteCustomerService;
|
|
|
+ @DubboReference
|
|
|
+ private final RemotePetService remotePetService;
|
|
|
+ @DubboReference
|
|
|
+ private final RemoteStoreService remoteStoreService;
|
|
|
+ @DubboReference
|
|
|
+ private final RemoteFulfillerService remoteFulfillerService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public TableDataInfo<SysSubOrderListPageVo> list(SysSubOrderListPageBo bo, PageQuery pageQuery) {
|
|
|
+
|
|
|
+ LambdaQueryWrapper<SysOrder> orderWrapper = Wrappers.lambdaQuery(SysOrder.class);
|
|
|
+
|
|
|
+ if (StringUtils.isNotBlank(bo.getContent())) {
|
|
|
+ List<Long> userIds = remoteUserService.selectUserIdsByName(bo.getContent());
|
|
|
+ orderWrapper.in(SysOrder::getOrderPlacer, WrapperUtils.convertIds(userIds));
|
|
|
+ List<Long> customerIds = remoteCustomerService.selectIdsByName(bo.getContent());
|
|
|
+ orderWrapper.in(SysOrder::getUsrCustomer, WrapperUtils.convertIds(customerIds));
|
|
|
+ }
|
|
|
+
|
|
|
+ Page<SysSubOrder> page = baseMapper.selectPage(
|
|
|
+ pageQuery.build(),
|
|
|
+ Wrappers.lambdaQuery(SysSubOrder.class).orderByDesc(SysSubOrder::getId)
|
|
|
+ .eq(bo.getStatus() != null, SysSubOrder::getStatus, bo.getStatus())
|
|
|
+ .eq(bo.getService() != null, SysSubOrder::getService, bo.getService())
|
|
|
+ );
|
|
|
+
|
|
|
+ List<Long> petIds = new ArrayList<>();
|
|
|
+ List<Long> storeIds = new ArrayList<>();
|
|
|
+ List<Long> customerIds = new ArrayList<>();
|
|
|
+ List<Long> userIds = new ArrayList<>();
|
|
|
+ List<Long> fulfillerIds = new ArrayList<>();
|
|
|
+ page.getRecords().forEach(e -> {
|
|
|
+ petIds.add(e.getUsrPet());
|
|
|
+ customerIds.add(e.getUsrCustomer());
|
|
|
+ storeIds.add(e.getStore());
|
|
|
+ userIds.add(e.getOrderPlacer());
|
|
|
+ if (e.getFulfiller() != null) {
|
|
|
+ fulfillerIds.add(e.getFulfiller());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ Map<Long, RemotePetVo> petMap = new HashMap<>();
|
|
|
+ Map<Long, RemoteStoreVo> storeMap = new HashMap<>();
|
|
|
+ Map<Long, RemoteCustomerVo> customerMap = new HashMap<>();
|
|
|
+ Map<Long, RemoteUserVo> userMap = new HashMap<>();
|
|
|
+ Map<Long, RemoteFulfillerVo> fulfillerMap = new HashMap<>();
|
|
|
+ remotePetService.getByIds(petIds).forEach(e -> petMap.put(e.getId(), e));
|
|
|
+ remoteStoreService.getByIds(storeIds).forEach(e -> storeMap.put(e.getId(), e));
|
|
|
+ remoteUserService.getByIds(userIds).forEach(e -> userMap.put(e.getUserId(), e));
|
|
|
+ remoteCustomerService.getByIds(customerIds).forEach(e -> customerMap.put(e.getId(), e));
|
|
|
+ remoteFulfillerService.getByIds(fulfillerIds).forEach(e -> fulfillerMap.put(e.getId(), e));
|
|
|
+
|
|
|
+ return TableDataInfo.build(page.convert(e -> {
|
|
|
+ SysSubOrderListPageVo vo = new SysSubOrderListPageVo();
|
|
|
+ vo.setId(e.getId());
|
|
|
+ vo.setCode(e.getCode());
|
|
|
+ vo.setService(e.getService());
|
|
|
+ vo.setMode(e.getMode());
|
|
|
+ vo.setType(e.getType());
|
|
|
+ vo.setPet(e.getUsrPet());
|
|
|
+ RemotePetVo pet = petMap.get(e.getUsrPet());
|
|
|
+ vo.setPetName(pet.getName());
|
|
|
+ vo.setPetBreed(pet.getBreed());
|
|
|
+ vo.setCustomer(e.getUsrCustomer());
|
|
|
+ RemoteCustomerVo customer = customerMap.get(e.getUsrCustomer());
|
|
|
+ vo.setCustomerName(customer.getName());
|
|
|
+ vo.setToAddress(e.getToAddress());
|
|
|
+ vo.setSite(e.getStoreSite());
|
|
|
+ vo.setStore(e.getStore());
|
|
|
+ RemoteStoreVo store = storeMap.get(e.getStore());
|
|
|
+ vo.setStoreName(store.getName());
|
|
|
+ vo.setPlacer(e.getOrderPlacer());
|
|
|
+ RemoteUserVo placer = userMap.get(e.getOrderPlacer());
|
|
|
+ vo.setPlacerUsername(placer.getUserName());
|
|
|
+ vo.setCreateTime(e.getCreateTime());
|
|
|
+ vo.setStatus(e.getStatus());
|
|
|
+ vo.setFulfiller(e.getFulfiller());
|
|
|
+ RemoteFulfillerVo fulfiller = fulfillerMap.get(e.getFulfiller());
|
|
|
+ vo.setFulfillerName(fulfiller != null ? fulfiller.getName() : null);
|
|
|
+ vo.setPrice(e.getPrice());
|
|
|
+ return vo;
|
|
|
+ }));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Override
|
|
|
+ public boolean dispatch(SysSubOrderDispatchBo bo) {
|
|
|
+
|
|
|
+ SysSubOrder subOrder = baseMapper.selectById(bo.getOrderId());
|
|
|
+ subOrder.setFulfiller(bo.getFulfiller());
|
|
|
+ subOrder.setPrice(bo.getPrice());
|
|
|
+ subOrder.setStatus(OrderStatusEnum.PENDING_ACCEPT.getValue());
|
|
|
+
|
|
|
+ boolean orderFlag = baseMapper.updateById(subOrder) == 0;
|
|
|
+ if (orderFlag) {
|
|
|
+ throw new RuntimeException("修改订单失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ FulfillerLoginUser fulfiller = remoteFulfillerService.getFulfillerById(bo.getFulfiller());
|
|
|
+
|
|
|
+ SysSubOrderLog log = new SysSubOrderLog();
|
|
|
+ log.setSubOrderId(bo.getOrderId());
|
|
|
+ log.setActioner(LoginHelper.getUserId());
|
|
|
+ log.setActionerType(OrderLogActionerTypeEnum.SYS_USER.getValue());
|
|
|
+ log.setLogType(OrderLogTypeEnum.ORDER.getValue());
|
|
|
+ log.setActionType(OrderLogActionTypeEnum.DISPATCH.getValue());
|
|
|
+ log.setTitle(OrderLogActionTypeEnum.DISPATCH.getLabel());
|
|
|
+ log.setContent("指派给 " + fulfiller.getName());
|
|
|
+ log.setTenantId(subOrder.getTenantId());
|
|
|
+ boolean logFlag = subOrderLogMapper.insert(log) == 0;
|
|
|
+ if (logFlag) {
|
|
|
+ throw new RuntimeException("记录日志失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean cancel(SysSubOrderCancelBo bo) {
|
|
|
+ return baseMapper.update(
|
|
|
+ Wrappers.lambdaUpdate(SysSubOrder.class)
|
|
|
+ .eq(SysSubOrder::getId, bo.getOrderId())
|
|
|
+ .set(SysSubOrder::getStatus, OrderStatusEnum.CANCELLED.getValue())
|
|
|
+ ) > 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public SysSubOrderVo getInfo(Long id) {
|
|
|
+ return baseMapper.selectVoById(id);
|
|
|
+ }
|
|
|
+}
|