package cn.iocoder.yudao.module.smartfactory.service.packagedata;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.smartfactory.controller.admin.packagedata.vo.PackageDataPageReqVO;
import cn.iocoder.yudao.module.smartfactory.controller.admin.packagedata.vo.PackageDataSaveReqVO;
import cn.iocoder.yudao.module.smartfactory.dal.dataobject.packagedata.PackageDataDO;
import cn.iocoder.yudao.module.smartfactory.dal.mysql.packagedata.PackageDataMapper;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;


/**
 * 打包线数据 Service 实现类
 *
 * @author 艾楷
 */
@Service
@Validated
public class PackageDataServiceImpl implements PackageDataService {

    @Resource
    private PackageDataMapper packageDataMapper;

    @Override
    public Long createPackageData(PackageDataSaveReqVO createReqVO) {
        // 插入
        PackageDataDO packageData = BeanUtils.toBean(createReqVO, PackageDataDO.class);
        packageDataMapper.insert(packageData);
        // 返回
        return packageData.getId();
    }

    @Override
    public void updatePackageData(PackageDataSaveReqVO updateReqVO) {
        // 更新
        PackageDataDO updateObj = BeanUtils.toBean(updateReqVO, PackageDataDO.class);
        packageDataMapper.updateById(updateObj);
    }

    @Override
    public void deletePackageData(Long id) {
        // 删除
        packageDataMapper.deleteById(id);
    }

    @Override
    public PackageDataDO getPackageData(Long id) {
        return packageDataMapper.selectById(id);
    }

    @Override
    public PageResult<PackageDataDO> getPackageDataPage(PackageDataPageReqVO pageReqVO) {
        return packageDataMapper.selectPage(pageReqVO);
    }

    @Override
    public List<PackageDataDO> getFactoryPackLineInfo(Long factoryId) {
        return packageDataMapper.selectList(new LambdaQueryWrapperX<PackageDataDO>().eq(PackageDataDO::getFactoryId, factoryId));
    }

    @Override
    public List<PackageDataDO> getFactoryPackLineInfoByTime(Long factoryId, Date beginTime, Date endTime) {
        return packageDataMapper.selectList(new LambdaQueryWrapperX<PackageDataDO>().eq(PackageDataDO::getFactoryId, factoryId)
                .ge(PackageDataDO::getCreateTime, beginTime)
                .le(PackageDataDO::getCreateTime, endTime));
    }

}