package com.ruoyi.frequency.mallorderstatus.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.enums.mallorder.MallOrderStatusEnums;
import com.ruoyi.frequency.mallorder.entity.MallOrder;
import com.ruoyi.frequency.mallorderstatus.entity.MallOrderStatus;
import com.ruoyi.frequency.mallorderstatus.mapper.MallOrderStatusMapper;
import com.ruoyi.frequency.mallorderstatus.service.MallOrderStatusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 订单流程Service业务层处理
 *
 * @author liwenlong
 * @date 2024-01-25
 */
@Service
public class MallOrderStatusServiceImpl extends ServiceImpl<MallOrderStatusMapper, MallOrderStatus>  implements MallOrderStatusService
{
    @Autowired
    private MallOrderStatusMapper mallOrderStatusMapper;

    /**
     * 查询订单流程
     *
     * @param id 订单流程主键
     * @return 订单流程
     */
    @Override
    public MallOrderStatus selectMallOrderStatusById(Long id)
    {
        return mallOrderStatusMapper.selectMallOrderStatusById(id);
    }

    /**
     * 查询订单流程列表
     *
     * @param mallOrderStatus 订单流程
     * @return 订单流程
     */
    @Override
    public List<MallOrderStatus> selectMallOrderStatusList(MallOrderStatus mallOrderStatus)
    {
        return mallOrderStatusMapper.selectMallOrderStatusList(mallOrderStatus);
    }

    /**
     * 新增订单流程
     *
     * @param mallOrderStatus 订单流程
     * @return 结果
     */
    @Override
    public int insertMallOrderStatus(MallOrderStatus mallOrderStatus)
    {
        mallOrderStatus.setCreateData();
        return mallOrderStatusMapper.insert(mallOrderStatus);
    }

    /**
     * 修改订单流程
     *
     * @param mallOrderStatus 订单流程
     * @return 结果
     */
    @Override
    public int updateMallOrderStatus(MallOrderStatus mallOrderStatus)
    {
        mallOrderStatus.setUpdateData();
        return mallOrderStatusMapper.updateMallOrderStatus(mallOrderStatus);
    }

    /**
     * 批量删除订单流程
     *
     * @param ids 需要删除的订单流程主键
     * @return 结果
     */
    @Override
    public int deleteMallOrderStatusByIds(Long[] ids,Integer delFlag)
    {
        this.lambdaUpdate().set(MallOrderStatus::getDelFlag,delFlag).in(MallOrderStatus::getId,ids).update();
        return ids.length;
    }

    @Override
    public void recordOrderStatus(MallOrder order, MallOrderStatusEnums orderStatusEnums) {
        MallOrderStatus orderStatus = new MallOrderStatus();
        orderStatus.setStatus(orderStatusEnums.getCode());
        orderStatus.setCreateTime(new Date());
        orderStatus.setOrderType(1);
        orderStatus.setName(orderStatusEnums.getName());
        orderStatus.setOrderId(order.getId());
        this.save(orderStatus);
    }
}
