package com.fjhx.service.order.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fjhx.entity.order.OrderFollow;
import com.fjhx.entity.order.OrderInfo;
import com.fjhx.mapper.order.OrderFollowMapper;
import com.fjhx.params.order.OrderFollowVo;
import com.fjhx.service.order.OrderFollowService;
import com.fjhx.service.order.OrderInfoService;
import com.fjhx.utils.wrapperUtil.IWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Map;

/**
 * <p>
 * 售后跟进 服务实现类
 * </p>
 *
 * @author ${author}
 * @since 2022-12-16
 */
@Service
public class OrderFollowServiceImpl extends ServiceImpl<OrderFollowMapper, OrderFollow> implements OrderFollowService {

    @Autowired
    private OrderInfoService orderInfoService;

    @Override
    public Page<OrderFollow> getPage(Map<String, Object> condition) {

        IWrapper<OrderFollow> wrapper = IWrapper.getWrapper(condition);

        return page(condition, wrapper);
    }

    @Override
    public void add(OrderFollowVo orderFollowVo) {
        save(orderFollowVo);
    }

    @Override
    public void edit(OrderFollowVo orderFollowVo) {
        updateById(orderFollowVo);
    }

    @Override
    public void delete(OrderFollowVo orderFollowVo) {
        removeById(orderFollowVo.getId());
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void followUp(OrderFollow orderFollow) {
        save(orderFollow);

        OrderInfo orderInfo = new OrderInfo();
        orderInfo.setId(orderFollow.getOrderInfoId());
        orderInfo.setAfterSalesStatus(orderFollow.getAfterSalesStatus());
        orderInfoService.updateById(orderInfo);
    }

}
