Pu Zhibing
2025-04-03 1f09f6daaf73bc83cceb4ae22b862b7b365635cf
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
package com.ruoyi.other.service.impl;
 
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.security.service.TokenService;
import com.ruoyi.order.feignClient.OrderClient;
import com.ruoyi.order.feignClient.RemoteOrderGoodsClient;
import com.ruoyi.order.model.Order;
import com.ruoyi.other.mapper.GoodsEvaluateMapper;
import com.ruoyi.other.api.domain.GoodsEvaluate;
import com.ruoyi.other.service.GoodsEvaluateService;
import com.ruoyi.other.vo.GoodsEvaluateVO;
import com.ruoyi.system.api.model.LoginUser;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;
 
/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author luodangjia
 * @since 2024-11-20
 */
@Service
public class GoodsEvaluateServiceImpl extends ServiceImpl<GoodsEvaluateMapper, GoodsEvaluate> implements GoodsEvaluateService {
    @Resource
    private RemoteOrderGoodsClient remoteOrderGoodsClient;
    @Resource
    private TokenService tokenService;
    @Resource
    private OrderClient orderClient;
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void addGoodsEvaluate(GoodsEvaluateVO goodsEvaluateVO) {
        List<GoodsEvaluate> evaluates = goodsEvaluateVO.getEvaluates();
        for (GoodsEvaluate goodsEvaluate : evaluates) {
            goodsEvaluate.setStatus(2);
            if (StringUtils.isNotEmpty(goodsEvaluate.getIdStr())){
                goodsEvaluate.setId(Long.valueOf(goodsEvaluate.getIdStr()));
                updateById(goodsEvaluate);
            }else {
                LoginUser loginUserApplet = tokenService.getLoginUserApplet();
                goodsEvaluate.setAppUserId(loginUserApplet.getUserid());
                goodsEvaluate.setCreateTime(LocalDateTime.now());
                save(goodsEvaluate);
            }
        }
        if (CollectionUtil.isNotEmpty(evaluates)){
            Long orderId = goodsEvaluateVO.getEvaluates().get(0).getOrderId();
            Order data = orderClient.getOrderById(orderId).getData();
            Order order = new Order();
            order.setId(data.getId());
            order.setOldOrderStatus(data.getOrderStatus());
            order.setOrderStatus(8);
            R<Void> r = remoteOrderGoodsClient.updateOrderStatus(order);
            if (R.isError(r)){
                throw new RuntimeException("修改订单状态失败");
            }
        }
 
    }
}