xin
2025-10-17 ab0637e981ab4c85120ccde35ee24ec4abbe3e24
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
package com.oying.modules.message.service.impl;
 
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.oying.modules.message.domain.MesCustomerCommentMsg;
import com.oying.modules.message.domain.dto.MesCustomerCommentMsgQueryCriteria;
import com.oying.modules.message.domain.myDto.MesCustomerCommentMsgDTO;
import com.oying.modules.message.mapper.MesCustomerCommentMsgMapper;
import com.oying.modules.message.service.MesCustomerCommentMsgService;
import com.oying.utils.FileUtil;
import com.oying.utils.PageResult;
import com.oying.utils.PageUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
 
/**
 * @author 李萌
 * @description 服务实现
 * @date 2025-07-25
 **/
@Service
@RequiredArgsConstructor
public class MesCustomerCommentMsgServiceImpl extends ServiceImpl<MesCustomerCommentMsgMapper, MesCustomerCommentMsg> implements MesCustomerCommentMsgService {
 
    private final MesCustomerCommentMsgMapper mesCustomerCommentMsgMapper;
 
    @Override
    public PageResult<MesCustomerCommentMsg> queryAll(MesCustomerCommentMsgQueryCriteria criteria, Page<Object> page) {
        return PageUtil.toPage(mesCustomerCommentMsgMapper.findAll(criteria, page));
    }
 
    @Override
    public List<MesCustomerCommentMsg> queryAll(MesCustomerCommentMsgQueryCriteria criteria) {
        return mesCustomerCommentMsgMapper.findAll(criteria);
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void create(MesCustomerCommentMsg resources) {
        mesCustomerCommentMsgMapper.insert(resources);
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void update(MesCustomerCommentMsg resources) {
        MesCustomerCommentMsg mesCustomerCommentMsg = getById(resources.getId());
        mesCustomerCommentMsg.copy(resources);
        mesCustomerCommentMsgMapper.updateById(mesCustomerCommentMsg);
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteAll(List<Long> ids) {
        mesCustomerCommentMsgMapper.deleteBatchIds(ids);
    }
 
    @Override
    public void download(List<MesCustomerCommentMsg> all, HttpServletResponse response) throws IOException {
        List<Map<String, Object>> list = new ArrayList<>();
        for (MesCustomerCommentMsg mesCustomerCommentMsg : all) {
            Map<String, Object> map = new LinkedHashMap<>();
            map.put("对应 mes_msg_record.id", mesCustomerCommentMsg.getMsgRecordId());
            map.put("店铺ID", mesCustomerCommentMsg.getShopId());
            map.put("订单ID", mesCustomerCommentMsg.getOrderId());
            map.put("订单编号 冗余", mesCustomerCommentMsg.getOrderNo());
            map.put("买家用户ID", mesCustomerCommentMsg.getBuyerId());
            map.put("买家昵称 冗余", mesCustomerCommentMsg.getBuyerName());
            map.put("评价ID 冗余", mesCustomerCommentMsg.getEvaluationId());
            map.put("商户是否已回复 0=未回复 1=已回复", mesCustomerCommentMsg.getReplied());
            map.put("创建人", mesCustomerCommentMsg.getCreateBy());
            map.put("创建时间", mesCustomerCommentMsg.getCreateTime());
            map.put("更新人", mesCustomerCommentMsg.getUpdateBy());
            map.put("更新时间", mesCustomerCommentMsg.getUpdateTime());
            list.add(map);
        }
        FileUtil.downloadExcel(list, response);
    }
 
    @Override
    public List<MesCustomerCommentMsgDTO> listCustomerComment(Long shopId) {
        return mesCustomerCommentMsgMapper.listCustomerComment(shopId);
    }
 
 
    //订单消息 插入对应字段
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void insertOrderMsg(MesCustomerCommentMsg resources) {
        //先临时对象
        MesCustomerCommentMsg mesCustomerCommentMsg = new MesCustomerCommentMsg();
        //对象属性非空则插入
        if (resources.getMsgRecordId() != null) {
            mesCustomerCommentMsg.setMsgRecordId(resources.getMsgRecordId());
        }
        if (resources.getShopId() != null) {
            mesCustomerCommentMsg.setShopId(resources.getShopId());
        }
        if (resources.getOrderId() != null) {
            mesCustomerCommentMsg.setOrderId(resources.getOrderId());
        }
        if (resources.getOrderNo() != null) {
            mesCustomerCommentMsg.setOrderNo(resources.getOrderNo());
        }
        if (resources.getBuyerId() != null) {
            mesCustomerCommentMsg.setBuyerId(resources.getBuyerId());
        }
        if (resources.getBuyerName() != null) {
            mesCustomerCommentMsg.setBuyerName(resources.getBuyerName());
        }
 
 
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void insertOrderMsgDetail(Long shopId, Long orderId, String orderNo, String buyerId, String buyerName, String commentContent, String replyContent) {
        // 插入具体字段  店铺id 订单编号 订单id 买家id 买家姓名 留言内容 回复内容
        // 先临时对象
        MesCustomerCommentMsg mesCustomerCommentMsg = new MesCustomerCommentMsg();
 
        // 设置对象属性 非空则插入 注意要有异常判断
        if (shopId != null) {
            mesCustomerCommentMsg.setShopId(shopId);
        }
        if (orderId != null) {
            mesCustomerCommentMsg.setOrderId(orderId);
        }
        if (orderNo != null) {
            mesCustomerCommentMsg.setOrderNo(orderNo);
        }
        if (buyerId != null) {
            mesCustomerCommentMsg.setBuyerId(buyerId);
        }
        if (buyerName != null) {
            mesCustomerCommentMsg.setBuyerName(buyerName);
        }
        if (commentContent != null) {
            mesCustomerCommentMsg.setCommentContent(commentContent);
        }
        if (replyContent != null) {
            mesCustomerCommentMsg.setReplyContent(replyContent);
            // 如果有回复内容,则标记为已回复
            mesCustomerCommentMsg.setReplied(1);
        } else {
            // 如果没有回复内容,则标记为未回复
            mesCustomerCommentMsg.setReplied(0);
        }
 
        // 设置创建时间
// 设置创建时间 - 使用 Timestamp 的标准写法
        mesCustomerCommentMsg.setCreateTime(new Timestamp(System.currentTimeMillis()));
 
 
        // 插入数据
        mesCustomerCommentMsgMapper.insert(mesCustomerCommentMsg);
    }
 
}