package cn.estsh.i3plus.ext.mes.apiservice.serviceimpl.base;

import cn.estsh.i3plus.ext.mes.api.base.IBomTakeEffectRecordService;
import cn.estsh.i3plus.ext.mes.pojo.bean.MesBomTakeEffectRecord;
import cn.estsh.i3plus.ext.mes.pojo.repository.MesBomTakeEffectRecordRepository;
import cn.estsh.i3plus.pojo.base.bean.DdlPackBean;
import cn.estsh.i3plus.pojo.base.bean.ListPager;
import cn.estsh.i3plus.pojo.base.common.Pager;
import cn.estsh.i3plus.pojo.base.common.PagerHelper;
import cn.estsh.i3plus.pojo.base.tool.DdlPreparedPack;
import cn.estsh.i3plus.pojo.mes.sqlpack.MesHqlPack;
import cn.estsh.impp.framework.boot.auth.AuthUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 文件描述
 *
 * @author xiangming.liao
 * @date 2021年05月06日 10:29
 */
@Service
public class BomTakeEffectRecordService implements IBomTakeEffectRecordService {
    @Autowired
    private MesBomTakeEffectRecordRepository bomTakeEffectRecordRepository;

    @Override
    public ListPager<MesBomTakeEffectRecord> queryByPager(MesBomTakeEffectRecord bomTakeEffectRecord, Pager pager) {
        DdlPackBean packBean = MesHqlPack.getMesAllData(AuthUtil.getOrganizeCode());
        DdlPreparedPack.getNumEqualPack(bomTakeEffectRecord.getIsValid(), "isValid", packBean);
        DdlPreparedPack.getStringEqualPack(bomTakeEffectRecord.getPartNo(), "partNo", packBean);
        DdlPreparedPack.getStringLikeEqualPack(bomTakeEffectRecord.getWorkOrderNo(), "workOrderNo", packBean);
        DdlPreparedPack.timeBuilder(bomTakeEffectRecord.getCreateDateTimeStart(), bomTakeEffectRecord.getCreateDateTimeEnd(), "createDatetime", packBean, true);
        pager = PagerHelper.getPager(pager, bomTakeEffectRecordRepository.findByHqlWhereCount(packBean));
        return new ListPager(bomTakeEffectRecordRepository.findByHqlWherePage(packBean, pager), pager);
    }
}
