Pu Zhibing
2024-12-17 d53c16a12e612a95dc8f6fb248e3669cbc441eb4
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/GoodsEvaluateServiceImpl.java
@@ -3,12 +3,15 @@
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.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;
@@ -27,15 +30,24 @@
public class GoodsEvaluateServiceImpl extends ServiceImpl<GoodsEvaluateMapper, GoodsEvaluate> implements GoodsEvaluateService {
    @Resource
    private RemoteOrderGoodsClient remoteOrderGoodsClient;
    @Resource
    private TokenService tokenService;
    @Override
    @Transactional
    @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());
                save(goodsEvaluate);
            }
        }
        this.saveBatch(evaluates);
        if (CollectionUtil.isNotEmpty(evaluates)){
            Order order = new Order();
            order.setId(goodsEvaluateVO.getEvaluates().get(0).getOrderId());