xin
2025-07-17 8c551068472e529a98b3eb27c9e347a924e48bf8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package com.oying.modules.sh.service.impl;
 
import com.alibaba.fastjson2.JSON;
import com.oying.modules.sh.domain.OrderOperationLog;
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.service.OrderOperationLogService;
import com.oying.modules.sh.domain.dto.OrderOperationLogQueryCriteria;
import com.oying.modules.sh.mapper.OrderOperationLogMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
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;
 
/**
 * @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) {
        return PageUtil.toPage(orderOperationLogMapper.findAll(criteria, page));
    }
 
    @Override
    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(OrderResponse response, OrderStatusEnum statusEnum, String cardName) {
        String userType = ConstantsKey.BUYER;
        String username = null;
        switch (statusEnum) {
            case ZERO:
            case ONE:
            case EIGHT:
            case NINE:
                userType = ConstantsKey.BUYER;
                break;
            case TWO:
                username = response.getOrder().getUsername();
            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;
                break;
            default:
        }
        if (username == null) {
            username = SecurityUtils.getCurrentUsername();
        }
        Timestamp time = new Timestamp(System.currentTimeMillis());
        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
    @Transactional(rollbackFor = Exception.class)
    public void update(OrderOperationLog resources) {
        OrderOperationLog orderOperationLog = getById(resources.getLogId());
        orderOperationLog.copy(resources);
        orderOperationLogMapper.updateById(orderOperationLog);
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteAll(List<Long> ids) {
        orderOperationLogMapper.deleteBatchIds(ids);
    }
 
    @Override
    public void download(List<OrderOperationLog> all, HttpServletResponse response) throws IOException {
        List<Map<String, Object>> list = new ArrayList<>();
        for (OrderOperationLog orderOperationLog : all) {
            Map<String, Object> map = new LinkedHashMap<>();
            map.put("用户账号", orderOperationLog.getUsername());
            map.put("用户类型", orderOperationLog.getUserType());
            map.put("用户操作", orderOperationLog.getOperation());
            map.put("备注", orderOperationLog.getRemark());
            map.put("操作时的订单快照", orderOperationLog.getSnapshotData());
            map.put("操作时间", orderOperationLog.getOperationTime());
            map.put("订单号", orderOperationLog.getOrderNum());
            list.add(map);
        }
        FileUtil.downloadExcel(list, response);
    }
}