| | |
| | | package com.oying.modules.sh.service.impl; |
| | | |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.oying.exception.BadRequestException; |
| | | import com.oying.modules.sh.domain.OrderOperationLog; |
| | | import com.oying.utils.FileUtil; |
| | | import com.oying.modules.sh.domain.vo.OrderResponse; |
| | | import com.oying.modules.sh.mapper.OrderMapper; |
| | | import com.oying.utils.*; |
| | | import com.oying.utils.enums.OrderStatusEnum; |
| | | import lombok.RequiredArgsConstructor; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | |
| | | import com.oying.modules.sh.mapper.OrderOperationLogMapper; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import com.oying.utils.PageUtil; |
| | | |
| | | import java.sql.Timestamp; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.io.IOException; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.util.ArrayList; |
| | | import java.util.LinkedHashMap; |
| | | import com.oying.utils.PageResult; |
| | | |
| | | /** |
| | | * @description 服务实现 |
| | | * @author lixin |
| | | * @date 2025-06-11 |
| | | **/ |
| | | * @author lixin |
| | | * @description 服务实现 |
| | | * @date 2025-06-11 |
| | | **/ |
| | | @Service |
| | | @RequiredArgsConstructor |
| | | public class OrderOperationLogServiceImpl extends ServiceImpl<OrderOperationLogMapper, OrderOperationLog> implements OrderOperationLogService { |
| | | |
| | | private final OrderOperationLogMapper orderOperationLogMapper; |
| | | private final OrderMapper orderMapper; |
| | | |
| | | @Override |
| | | public PageResult<OrderOperationLog> queryAll(OrderOperationLogQueryCriteria criteria, Page<Object> page){ |
| | | public PageResult<OrderOperationLog> queryAll(OrderOperationLogQueryCriteria criteria, Page<Object> page) { |
| | | return PageUtil.toPage(orderOperationLogMapper.findAll(criteria, page)); |
| | | } |
| | | |
| | | @Override |
| | | public List<OrderOperationLog> queryAll(OrderOperationLogQueryCriteria criteria){ |
| | | public List<OrderOperationLog> queryAll(OrderOperationLogQueryCriteria criteria) { |
| | | return orderOperationLogMapper.findAll(criteria); |
| | | } |
| | | |
| | | @Override |
| | | public List<OrderOperationLog> getByOrderNum(String orderNum) { |
| | | return orderOperationLogMapper.getByOrderNum(orderNum); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void create(OrderOperationLog resources) { |
| | | public synchronized void create(OrderResponse response, OrderStatusEnum statusEnum, String cardName) { |
| | | String userType = ConstantsKey.BUYER; |
| | | String username = null; |
| | | Timestamp time = new Timestamp(System.currentTimeMillis()); |
| | | switch (statusEnum) { |
| | | case NINE: |
| | | if (response.getOrder().getOrderStatus().equals(OrderStatusEnum.NINE.getKey())) { |
| | | throw new BadRequestException("订单已取消"); |
| | | } |
| | | if (response.getOrder().getOrderStatus() > OrderStatusEnum.TWO.getKey()) { |
| | | throw new BadRequestException(OrderStatusEnum.getValue(response.getOrder().getOrderStatus())); |
| | | } |
| | | case ZERO: |
| | | case ONE: |
| | | case EIGHT: |
| | | userType = ConstantsKey.BUYER; |
| | | break; |
| | | case TWO: |
| | | username = response.getOrder().getUsername(); |
| | | OrderOperationLog log1 = new OrderOperationLog(); |
| | | log1.setOrderNum(response.getOrder().getOrderNum()); |
| | | log1.setUsername(username); |
| | | log1.setUserType(userType); |
| | | log1.setOperation(OrderStatusEnum.ONE.getKey()); |
| | | log1.setOperationDescribe(OrderStatusEnum.ONE.getValue()); |
| | | log1.setRemark(username + ":" + time + ">" + OrderStatusEnum.ONE.getValue() + ":" + response.getOrder().getOrderNum()); |
| | | Map<String, Object> map1 = new LinkedHashMap<>(); |
| | | response.getOrder().setOrderStatus(OrderStatusEnum.ONE.getKey()); |
| | | response.getOrder().setOrderStatusDescribe(OrderStatusEnum.ONE.getValue()); |
| | | map1.put("order", response.getOrder()); |
| | | map1.put("address", response.getAddress()); |
| | | log1.setSnapshotData(JSON.toJSONString(map1)); |
| | | log1.setOperationTime(time); |
| | | orderOperationLogMapper.insert(log1); |
| | | response.getOrder().setOrderStatus(OrderStatusEnum.TWO.getKey()); |
| | | response.getOrder().setOrderStatusDescribe(OrderStatusEnum.TWO.getValue()); |
| | | case FOUR: |
| | | userType = ConstantsKey.MERCHANT; |
| | | break; |
| | | case THREE: |
| | | orderMapper.updateRider(response.getOrder().getOrderNum(), SecurityUtils.getCurrentUserId(), SecurityUtils.getCurrentUsername(), cardName); |
| | | case FIVE: |
| | | case SIX: |
| | | case SEVEN: |
| | | userType = ConstantsKey.RIDER; |
| | | username = SecurityUtils.getCurrentUsername(); |
| | | OrderOperationLog log2 = new OrderOperationLog(); |
| | | log2.setOrderNum(response.getOrder().getOrderNum()); |
| | | log2.setUsername(username); |
| | | log2.setUserType(userType); |
| | | log2.setOperation(statusEnum.getKey()); |
| | | log2.setOperationDescribe(statusEnum.getValue()); |
| | | log2.setRemark(username + ":" + time + ">" + statusEnum.getValue() + ":" + response.getOrder().getOrderNum()); |
| | | Map<String, Object> map2 = new LinkedHashMap<>(); |
| | | map2.put("order", response.getOrder()); |
| | | map2.put("address", response.getAddress()); |
| | | log2.setSnapshotData(JSON.toJSONString(map2)); |
| | | log2.setOperationTime(time); |
| | | orderOperationLogMapper.insert(log2); |
| | | orderMapper.updateOrderStatus(response.getOrder().getOrderNum(), statusEnum.getKey(), statusEnum.getValue()); |
| | | statusEnum = OrderStatusEnum.EIGHT; |
| | | break; |
| | | default: |
| | | } |
| | | if (username == null) { |
| | | username = SecurityUtils.getCurrentUsername(); |
| | | } |
| | | OrderOperationLog resources = new OrderOperationLog(); |
| | | resources.setOrderNum(response.getOrder().getOrderNum()); |
| | | resources.setUsername(username); |
| | | resources.setUserType(userType); |
| | | resources.setOperation(statusEnum.getKey()); |
| | | resources.setOperationDescribe(statusEnum.getValue()); |
| | | resources.setRemark(username + ":" + time + ">" + statusEnum.getValue() + ":" + response.getOrder().getOrderNum()); |
| | | Map<String, Object> map = new LinkedHashMap<>(); |
| | | map.put("order", response.getOrder()); |
| | | map.put("address", response.getAddress()); |
| | | resources.setSnapshotData(JSON.toJSONString(map)); |
| | | resources.setOperationTime(time); |
| | | orderOperationLogMapper.insert(resources); |
| | | orderMapper.updateOrderStatus(response.getOrder().getOrderNum(), statusEnum.getKey(), statusEnum.getValue()); |
| | | } |
| | | |
| | | @Override |
| | |
| | | List<Map<String, Object>> list = new ArrayList<>(); |
| | | for (OrderOperationLog orderOperationLog : all) { |
| | | Map<String, Object> map = new LinkedHashMap<>(); |
| | | map.put("用户id", orderOperationLog.getUserId()); |
| | | map.put("用户账号", orderOperationLog.getUsername()); |
| | | map.put("用户类型", orderOperationLog.getUserType()); |
| | | map.put("用户操作", orderOperationLog.getOperation()); |
| | | map.put("备注", orderOperationLog.getRemark()); |