package com.xinelu.manage.service.trainingorder.impl;

import com.xinelu.manage.domain.trainingorder.TrainingOrder;
import com.xinelu.manage.domain.trainingorderitemdirectory.TrainingOrderItemDirectory;
import com.xinelu.manage.mapper.trainingorder.TrainingOrderMapper;
import com.xinelu.manage.mapper.trainingorderitemdirectory.TrainingOrderItemDirectoryMapper;
import com.xinelu.manage.service.trainingorder.ITrainingOrderService;
import com.xinelu.manage.vo.trainingorder.TrainingOrderVO;
import com.xinelu.common.constant.Constants;
import com.xinelu.common.core.domain.AjaxResult;
import com.xinelu.common.enums.TrainingItemTypeEnum;
import com.xinelu.common.utils.SecurityUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 学习培训订单Service业务层处理
 *
 * @author xinyilu
 * @date 2023-04-20
 */
@Service
public class TrainingOrderServiceImpl implements ITrainingOrderService {
    @Resource
    private TrainingOrderMapper trainingOrderMapper;
    @Resource
    private TrainingOrderItemDirectoryMapper trainingOrderItemDirectoryMapper;

    /**
     * 查询学习培训订单
     *
     * @param id 学习培训订单主键
     * @return 学习培训订单
     */
    @Override
    public TrainingOrderVO selectTrainingOrderById(Long id) {
        return trainingOrderMapper.selectTrainingOrderVoById(id);
    }

    /**
     * 查询学习培训订单列表
     *
     * @param trainingOrder 学习培训订单
     * @return 学习培训订单
     */
    @Override
    public List<TrainingOrderVO> selectTrainingOrderList(TrainingOrderVO trainingOrder) {
        trainingOrder.setTrainingParentId(Constants.TRAINING_PARENT_ID);
        return trainingOrderMapper.selectTrainingOrderVOList(trainingOrder);
    }

    /**
     * 新增学习培训订单
     *
     * @param trainingOrder 学习培训订单
     * @return 结果
     */
    @Override
    public int insertTrainingOrder(TrainingOrder trainingOrder) {
        trainingOrder.setCreateTime(LocalDateTime.now());
        trainingOrder.setCreateBy(SecurityUtils.getUsername());
        return trainingOrderMapper.insertTrainingOrder(trainingOrder);
    }

    /**
     * 修改学习培训订单
     *
     * @param trainingOrder 学习培训订单
     * @return 结果
     */
    @Override
    public int updateTrainingOrder(TrainingOrder trainingOrder) {
        trainingOrder.setUpdateTime(LocalDateTime.now());
        trainingOrder.setUpdateBy(SecurityUtils.getUsername());
        return trainingOrderMapper.updateTrainingOrder(trainingOrder);
    }

    /**
     * 批量删除学习培训订单
     *
     * @param ids 需要删除的学习培训订单主主键
     * @return 结果
     */
    @Override
    public int deleteTrainingOrderByIds(Long[] ids) {
        return trainingOrderMapper.deleteTrainingOrderByIds(ids);
    }

    /**
     * 退款信息查询
     *
     * @param id 学习培训订单主键
     * @return 结果
     */
    @Override
    public AjaxResult selectRefundInformation(Long id) {
        return AjaxResult.success(trainingOrderMapper.selectRefundInformation(id, TrainingItemTypeEnum.LEARNING_ITEM_GROUP.getInfo()));
    }

    /**
     * 查询订单明细章节信息
     *
     * @param trainingOrderItemDirectory 查询学习培训订单明细章节
     * @return List<TrainingOrderItemDirectory>
     */
    @Override
    public List<TrainingOrderItemDirectory> selectTrainingOrderItemDirectoryList(TrainingOrderItemDirectory trainingOrderItemDirectory) {
        return trainingOrderItemDirectoryMapper.selectTrainingOrderItemDirectoryList(trainingOrderItemDirectory);
    }
}
