package com.ruoyi.app.service.impl;

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

import com.ruoyi.app.DTO.SlaughterBatchDTO;
import com.ruoyi.app.domain.DistributeBatch;
import com.ruoyi.app.domain.HookBind;
import com.ruoyi.app.domain.request.ReqHookRegister;
import com.ruoyi.app.domain.request.ReqSlaughterBatch;
import com.ruoyi.app.mapper.DistributeBatchMapper;
import com.ruoyi.app.mapper.HookBindMapper;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.app.mapper.SlaughterBatchMapper;
import com.ruoyi.app.domain.SlaughterBatch;
import com.ruoyi.app.service.ISlaughterBatchService;

import javax.annotation.PostConstruct;

/**
 * 屠宰批次Service业务层处理
 * 
 * @author coede
 * @date 2025-03-19
 */
@Service
public class SlaughterBatchServiceImpl implements ISlaughterBatchService 
{
    @Autowired
    private SlaughterBatchMapper slaughterBatchMapper;

    //待删
//
//    @Autowired
//    private DistributeBatchMapper distributeBatchMapper;
//
//    @Autowired
//    private HookBindMapper hookBindMapper;
//
//    @PostConstruct
//    private void buildData(){
//        List<DistributeBatch> distributeBatches = distributeBatchMapper.selectDistributeBatchList(new DistributeBatch());
//
//        for(DistributeBatch item : distributeBatches){
//            HookBind hookBindReq = new HookBind();
//            hookBindReq.setDistributeBatchId(item.getId());
//            List<HookBind> hookBinds = hookBindMapper.selectHookBindList(hookBindReq);
//            Date slaughterTime = new Date();
//            if(hookBinds.size()>0){
//                slaughterTime = hookBinds.get(0).getBindTime();
//            }
//            ReqSlaughterBatch reqSlaughterBatch = new ReqSlaughterBatch();
//            reqSlaughterBatch.setDistributeBatchId(item.getId());
//            List<SlaughterBatchDTO> slaughterBatchList = slaughterBatchMapper.selectSlaughterBatchList(reqSlaughterBatch);
//            if(slaughterBatchList.size() > 0){
//                //更新时间
//                SlaughterBatch slaughterBatch = new SlaughterBatch();
//                slaughterBatch.setSlaughterTime(slaughterTime);
//                slaughterBatch.setId(slaughterBatchList.get(0).getId());
//                slaughterBatchMapper.updateSlaughterBatch(slaughterBatch);
//            }else{
//                //新增
//                SlaughterBatch slaughterBatch = new SlaughterBatch();
//                slaughterBatch.setSlaughterTime(slaughterTime);
//                slaughterBatch.setDistributeBatchId(item.getId());
//                slaughterBatch.setEntranceBatchId(item.getEntranceBatchId());
//                slaughterBatch.setSalePlace("1");
//                slaughterBatchMapper.insertSlaughterBatch(slaughterBatch);
//            }
//        }
//    }


    /**
     * 查询屠宰批次
     * 
     * @param id 屠宰批次主键
     * @return 屠宰批次
     */
    @Override
    public SlaughterBatchDTO selectSlaughterBatchById(Long id)
    {
        return slaughterBatchMapper.selectSlaughterBatchById(id);
    }

    /**
     * 查询屠宰批次列表
     * 
     * @param slaughterBatch 屠宰批次
     * @return 屠宰批次
     */
    @Override
    public List<SlaughterBatchDTO> selectSlaughterBatchList(ReqSlaughterBatch slaughterBatch)
    {
        return slaughterBatchMapper.selectSlaughterBatchList(slaughterBatch);
    }

    /**
     * 查询屠宰批次列表
     *
     * @param slaughterBatch 屠宰批次
     * @return 屠宰批次
     */
    @Override
    public List<SlaughterBatchDTO> exportSlaughterRelationList(ReqSlaughterBatch slaughterBatch)
    {
        return slaughterBatchMapper.selectSlaughterBatchList(slaughterBatch);
    }

    /**
     * 新增屠宰批次
     * 
     * @param slaughterBatch 屠宰批次
     * @return 结果
     */
    @Override
    public int insertSlaughterBatch(SlaughterBatch slaughterBatch)
    {
        slaughterBatch.setCreateTime(DateUtils.getNowDate());
        return slaughterBatchMapper.insertSlaughterBatch(slaughterBatch);
    }

    /**
     * 修改屠宰批次
     * 
     * @param slaughterBatch 屠宰批次
     * @return 结果
     */
    @Override
    public int updateSlaughterBatch(SlaughterBatch slaughterBatch)
    {
        slaughterBatch.setUpdateTime(DateUtils.getNowDate());
        return slaughterBatchMapper.updateSlaughterBatch(slaughterBatch);
    }

    /**
     * 批量删除屠宰批次
     * 
     * @param ids 需要删除的屠宰批次主键
     * @return 结果
     */
    @Override
    public int deleteSlaughterBatchByIds(Long[] ids)
    {
        return slaughterBatchMapper.deleteSlaughterBatchByIds(ids);
    }

    /**
     * 删除屠宰批次信息
     * 
     * @param id 屠宰批次主键
     * @return 结果
     */
    @Override
    public int deleteSlaughterBatchById(Long id)
    {
        return slaughterBatchMapper.deleteSlaughterBatchById(id);
    }
}
