package com.ruoyi.warehouse.check.service.impl;

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

import com.ruoyi.common.core.domain.entity.TWarehouse;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.warehouse.check.domain.TWarehouseCheckItems;
import com.ruoyi.warehouse.check.service.ITWarehouseCheckItemsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.warehouse.check.mapper.TWarehouseCheckMapper;
import com.ruoyi.warehouse.check.domain.TWarehouseCheck;
import com.ruoyi.warehouse.check.service.ITWarehouseCheckService;

/**
 * 巡检checkService业务层处理
 *
 * @author dongyongwei
 * @date 2021-07-21
 */
@Service
public class TWarehouseCheckServiceImpl implements ITWarehouseCheckService {
    @Autowired
    private TWarehouseCheckMapper tWarehouseCheckMapper;

    @Autowired
    private ITWarehouseCheckItemsService tWarehouseCheckItemsService;

    /**
     * 查询巡检check
     *
     * @param fId 巡检checkID
     * @return 巡检check
     */
    @Override
    public TWarehouseCheck selectTWarehouseCheckById(Long fId) {

        TWarehouseCheck tWarehouseCheck = tWarehouseCheckMapper.selectTWarehouseCheckById(fId);
        //增加返回明细数据
        TWarehouseCheckItems tWarehouseCheckItemsQuery = new TWarehouseCheckItems();
        tWarehouseCheckItemsQuery.setfCheckFid(fId);
        List<TWarehouseCheckItems> tWarehouseCheckItemsList = tWarehouseCheckItemsService.selectTWarehouseCheckItemsList(tWarehouseCheckItemsQuery);
        if (tWarehouseCheckItemsList.size() > 0) {
            tWarehouseCheck.settWarehouseCheckItemsList(tWarehouseCheckItemsList);
        }
        return tWarehouseCheck;
    }

    /**
     * 查询巡检check列表
     *
     * @param tWarehouseCheck 巡检check
     * @return 巡检check
     */
    @Override
    public List<TWarehouseCheck> selectTWarehouseCheckList(TWarehouseCheck tWarehouseCheck) {
        return tWarehouseCheckMapper.selectTWarehouseCheckList(tWarehouseCheck);
    }

    /**
     * 新增巡检check
     *
     * @param tWarehouseCheck 巡检check
     * @return 结果
     */
    @Override
    public Long insertTWarehouseCheck(TWarehouseCheck tWarehouseCheck) {
        tWarehouseCheck.setfCreateBy(SecurityUtils.getLoginUser().getUser().getUserId());
        tWarehouseCheck.setfCreateTime(new Date());
        tWarehouseCheckMapper.insertTWarehouseCheck(tWarehouseCheck);
        return tWarehouseCheck.getfId();
    }

    /**
     * 修改巡检check
     *
     * @param tWarehouseCheck 巡检check
     * @return 结果
     */
    @Override
    public int updateTWarehouseCheck(TWarehouseCheck tWarehouseCheck) {
        tWarehouseCheck.setfUpdateBy(SecurityUtils.getLoginUser().getUser().getUserId());
        tWarehouseCheck.setfUpdateTime(new Date());
        return tWarehouseCheckMapper.updateTWarehouseCheck(tWarehouseCheck);
    }

    /**
     * 批量删除巡检check
     *
     * @param fIds 需要删除的巡检checkID
     * @return 结果
     */
    @Override
    public int deleteTWarehouseCheckByIds(Long[] fIds) {
        return tWarehouseCheckMapper.deleteTWarehouseCheckByIds(fIds);
    }

    /**
     * 删除巡检check信息
     *
     * @param fId 巡检checkID
     * @return 结果
     */
    @Override
    public int deleteTWarehouseCheckById(Long fId) {
        return tWarehouseCheckMapper.deleteTWarehouseCheckById(fId);
    }

    /**
     * 获取主表内仓库清单
     */
    @Override
    public List<TWarehouse> selectTWarehouseListInCheck() {
        return tWarehouseCheckMapper.selectTWarehouseListInCheck();
    }
}
