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

import cn.estsh.i3plus.ext.mes.pcn.api.base.IMesWorkCellExtendCfgService;
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.enumutil.CommonEnumUtil;
import cn.estsh.i3plus.pojo.base.tool.DdlPreparedPack;
import cn.estsh.i3plus.pojo.base.util.StringUtil;
import cn.estsh.i3plus.pojo.mes.bean.MesWorkCellExtendCfg;
import cn.estsh.i3plus.pojo.mes.repository.MesWorkCellExtendCfgRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * @Description: 开关班记录表
 * @Author: gsz
 * @Date: 2024/5/21 14:16
 * @Modify:
 */
@Service
@Slf4j
public class MesWorkCellExtendCfgServiceImpl implements IMesWorkCellExtendCfgService {

    @Autowired
    private MesWorkCellExtendCfgRepository mesWorkCellExtendCfgRDao;

    @Override
    public ListPager<MesWorkCellExtendCfg> queryMesWorkCellExtendCfgByPager(MesWorkCellExtendCfg bean, Pager pager) {

        DdlPackBean packBean = DdlPackBean.getDdlPackBean(bean.getOrganizeCode());
        DdlPreparedPack.getStringEqualPack(bean.getWorkCenterCode(), "workCenterCode", packBean);
        DdlPreparedPack.getStringEqualPack(bean.getWorkCellCode(), "workCellCode", packBean);
        DdlPreparedPack.getNumEqualPack(bean.getExtendType(), "extendType", packBean);

        if(!StringUtil.isEmpty(bean.orderBy())){
            packBean.setOrderByStr(bean.orderBy());
        }else {
            DdlPreparedPack.getOrderByPack(new Object[]{CommonEnumUtil.ASC_OR_DESC.ASC.getValue()}, new String[]{"seq"}, packBean);
        }
        pager = PagerHelper.getPager(pager, mesWorkCellExtendCfgRDao.findByHqlWhereCount(packBean));

        List<MesWorkCellExtendCfg> resultList = mesWorkCellExtendCfgRDao.findByHqlWherePage(packBean, pager);

        return new ListPager<>(resultList, pager);
    }


    @Override
    public List<MesWorkCellExtendCfg>  queryMesWorkCellExtendCfg(MesWorkCellExtendCfg bean) {
        DdlPackBean packBean = DdlPackBean.getDdlPackBean(bean.getOrganizeCode());
        DdlPreparedPack.getStringEqualPack(bean.getAreaCode(), "areaCode", packBean);
        DdlPreparedPack.getStringEqualPack(bean.getWorkCenterCode(), "workCenterCode", packBean);
        DdlPreparedPack.getStringEqualPack(bean.getWorkCellCode(), "workCellCode", packBean);
        DdlPreparedPack.getNumEqualPack(StringUtil.isEmpty(bean.getExtendType())?20:bean.getExtendType(), "extendType", packBean);
        if(!StringUtil.isEmpty(bean.orderBy())){
            packBean.setOrderByStr(bean.orderBy());
        }else {
            DdlPreparedPack.getOrderByPack(new Object[]{CommonEnumUtil.ASC_OR_DESC.ASC.getValue()}, new String[]{"seq"}, packBean);
        }

        return mesWorkCellExtendCfgRDao.findByHqlWhere(packBean);
    }
}
