package com.ruoyi.system.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.DoumuProductFj;
import com.ruoyi.system.mapper.DoumuProductFjMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.DoumuEvaluateMapper;
import com.ruoyi.system.domain.DoumuEvaluate;
import com.ruoyi.system.service.IDoumuEvaluateService;

/**
 * 订单评价Service业务层处理
 * 
 * @author boman
 * @date 2024-01-22
 */
@Service
public class DoumuEvaluateServiceImpl implements IDoumuEvaluateService 
{
    @Autowired
    private DoumuEvaluateMapper doumuEvaluateMapper;

    @Autowired
    private DoumuProductFjMapper doumuProductFjMapper;

    /**
     * 查询订单评价
     * 
     * @param evaluateId 订单评价主键
     * @return 订单评价
     */
    @Override
    public DoumuEvaluate selectDoumuEvaluateByEvaluateId(Long evaluateId)
    {
        DoumuEvaluate doumuEvaluate = doumuEvaluateMapper.selectDoumuEvaluateByEvaluateId(evaluateId);
        //查询附件
        DoumuProductFj doumuProductFj = new DoumuProductFj();
        doumuProductFj.setProductId(doumuEvaluate.getProductId());
        doumuProductFj.setModule("2");
        List<DoumuProductFj> fjList = doumuProductFjMapper.selectDoumuProductFjList(doumuProductFj);
        doumuEvaluate.setFjList(fjList);

        return doumuEvaluate;
    }

    /**
     * 查询订单评价列表
     * 
     * @param doumuEvaluate 订单评价
     * @return 订单评价
     */
    @Override
    public List<DoumuEvaluate> selectDoumuEvaluateList(DoumuEvaluate doumuEvaluate)
    {
        return doumuEvaluateMapper.selectDoumuEvaluateList(doumuEvaluate);
    }

    /**
     * 新增订单评价
     * 
     * @param doumuEvaluate 订单评价
     * @return 结果
     */
    @Override
    public int insertDoumuEvaluate(DoumuEvaluate doumuEvaluate)
    {
        doumuEvaluate.setCreateTime(DateUtils.getNowDate());
        int i = doumuEvaluateMapper.insertDoumuEvaluate(doumuEvaluate);
        //保存附件
        List<DoumuProductFj> fjList = doumuEvaluate.getFjList();
        if(fjList!=null && fjList.size()>0){
            for (DoumuProductFj doumuProductFj : fjList) {
                doumuProductFj.setProductId(doumuEvaluate.getProductId());
                doumuProductFj.setModule("2");
                doumuProductFjMapper.insertDoumuProductFj(doumuProductFj);
            }
        }

        return i;
    }

    /**
     * 修改订单评价
     * 
     * @param doumuEvaluate 订单评价
     * @return 结果
     */
    @Override
    public int updateDoumuEvaluate(DoumuEvaluate doumuEvaluate)
    {
        doumuEvaluate.setUpdateTime(DateUtils.getNowDate());
        //先删除附件
        doumuProductFjMapper.deleteDoumuProductFjByProductId(doumuEvaluate.getProductId(),"2");

        //保存附件
        List<DoumuProductFj> fjList = doumuEvaluate.getFjList();
        if(fjList!=null && fjList.size()>0){
            for (DoumuProductFj doumuProductFj : fjList) {
                //再保存附件
                doumuProductFj.setProductId(doumuEvaluate.getProductId());
                doumuProductFj.setModule("2");
                doumuProductFjMapper.insertDoumuProductFj(doumuProductFj);
            }
        }

        return doumuEvaluateMapper.updateDoumuEvaluate(doumuEvaluate);
    }

    /**
     * 批量删除订单评价
     * 
     * @param evaluateIds 需要删除的订单评价主键
     * @return 结果
     */
    @Override
    public int deleteDoumuEvaluateByEvaluateIds(Long[] evaluateIds)
    {
        return doumuEvaluateMapper.deleteDoumuEvaluateByEvaluateIds(evaluateIds);
    }

    /**
     * 删除订单评价信息
     * 
     * @param evaluateId 订单评价主键
     * @return 结果
     */
    @Override
    public int deleteDoumuEvaluateByEvaluateId(Long evaluateId)
    {
        return doumuEvaluateMapper.deleteDoumuEvaluateByEvaluateId(evaluateId);
    }
}
