package com.prolog.eis.service.outbound.impl;

import com.prolog.eis.dao.outbound.BizOutboundTaskDetailMapper;
import com.prolog.eis.model.outbound.BizOutboundTaskDetail;
import com.prolog.eis.service.outbound.BizOutboundTaskDetailService;
import com.prolog.framework.core.restriction.Criteria;
import com.prolog.framework.core.restriction.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author zmr
 * @description: 出库任务详情表-服务实现类
 * @date 2023-07-06 11:36
 */
@Service
public class BizOutboundTaskDetailServiceImpl implements BizOutboundTaskDetailService {

    @Autowired
    private BizOutboundTaskDetailMapper bizOutboundTaskDetailMapper;

    /**
     * 新增数据
     *
     * @param bizOutboundTaskDetail 出库任务详情表
     */
    @Override
    public long save(BizOutboundTaskDetail bizOutboundTaskDetail) {
        return bizOutboundTaskDetailMapper.save(bizOutboundTaskDetail);
    }

    /**
     * 新增批量数据
     *
     * @param bizOutboundTaskDetailList 出库任务详情表
     */
    @Override
    public long saveBatch(List<BizOutboundTaskDetail> bizOutboundTaskDetailList) {
        return bizOutboundTaskDetailMapper.saveBatch(bizOutboundTaskDetailList);
    }

    /**
     * 查询多条数据
     *
     * @param paramMap 查询起始位置
     * @return 对象列表
     */
    @Override
    public List<BizOutboundTaskDetail> findByMap(Map<String, Object> paramMap) {
        return bizOutboundTaskDetailMapper.findByMap(paramMap, BizOutboundTaskDetail.class);
    }

    /**
     * 查询单条数据
     *
     * @param paramMap 查询起始位置
     * @return 对象
     */
    @Override
    public BizOutboundTaskDetail findOneByMap(Map<String, Object> paramMap) {
        List<BizOutboundTaskDetail> dataList = findByMap(paramMap);
        if(dataList.isEmpty()) {
            return null;
        }
        return dataList.get(0);
    }

    /**
     * 查询多条数据
     *
     * @param criteria 查询起始位置
     * @return 对象列表
     */
    @Override
    public List<BizOutboundTaskDetail> findByCriteria(Criteria criteria) {
        return bizOutboundTaskDetailMapper.findByCriteria(criteria);
    }

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public BizOutboundTaskDetail findById(int id) {
        return bizOutboundTaskDetailMapper.findById(id, BizOutboundTaskDetail.class);
    }

    /**
     * 修改数据
     *
     * @param bizOutboundTaskDetail 实例对象
     */
    @Override
    public long update(BizOutboundTaskDetail bizOutboundTaskDetail) {
        return bizOutboundTaskDetailMapper.update(bizOutboundTaskDetail);
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     */
    @Override
    public long deleteById(int id) {
        return bizOutboundTaskDetailMapper.deleteById(id, BizOutboundTaskDetail.class);
    }

    /**
     * 通过参数删除数据
     *
     * @param paramMap 参数
     */
    @Override
    public long deleteByMap(Map<String, Object> paramMap) {
        return bizOutboundTaskDetailMapper.deleteByMap(paramMap, BizOutboundTaskDetail.class);
    }

    /**
     * 通过参数查询总条数
     *
     * @param paramMap 参数
     */
    @Override
    public long findCountByMap(Map<String, Object> paramMap) {
        return bizOutboundTaskDetailMapper.findCountByMap(paramMap, BizOutboundTaskDetail.class);
    }

    @Override
    public void batchUpdate(List<BizOutboundTaskDetail> bizOutboundTaskDetailList) {
        for (BizOutboundTaskDetail bizOutboundTaskDetail : bizOutboundTaskDetailList) {
            bizOutboundTaskDetailMapper.update(bizOutboundTaskDetail);
        }
    }

    @Override
    public List<BizOutboundTaskDetail> findByOrderId(Integer orderId) {
        Criteria criteria = Criteria.forClass(BizOutboundTaskDetail.class);
        criteria.setRestriction(Restrictions.eq("outboundId", orderId));
        return bizOutboundTaskDetailMapper.findByCriteria(criteria);
    }


}
