package com.cf.imes.module.system.dal.mysql.process;

import com.cf.imes.framework.common.pojo.PageResult;
import com.cf.imes.framework.mybatis.core.mapper.BaseMapperX;
import com.cf.imes.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.cf.imes.module.system.controller.admin.process.vo.group.ProcessGroupPageReqVO;
import com.cf.imes.module.system.dal.dataobject.process.ProcessDO;
import com.cf.imes.module.system.dal.dataobject.process.ProcessGroupDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * 工序组表 process_group Mapper
 *
 * @author 晨丰科技
 */
@Mapper
public interface ProcessGroupMapper extends BaseMapperX<ProcessGroupDO> {

    default PageResult<ProcessGroupDO> selectPage(ProcessGroupPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<ProcessGroupDO>()
                .likeIfPresent(ProcessGroupDO::getName, reqVO.getName())
                .eqIfPresent(ProcessGroupDO::getIsDefault, reqVO.getIsDefault())
                .eqIfPresent(ProcessGroupDO::getSort, reqVO.getSort())
                .eqIfPresent(ProcessGroupDO::getItems, reqVO.getItems())
                .eqIfPresent(ProcessGroupDO::getOrganId, reqVO.getOrganId())
                .eqIfPresent(ProcessGroupDO::getDescription, reqVO.getDescription())
                .betweenIfPresent(ProcessGroupDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(ProcessGroupDO::getId));
    }

    ProcessDO selectOneById(@Param("id") Long id, @Param("organId") Long organId);

    int updateIsDefault(@Param("processGroupId") Long processGroupId, @Param("organId") Long organId);

//    模糊匹配items
    default List<ProcessGroupDO> selectListByItems(@Param("items") String items) {
        return selectList(new LambdaQueryWrapperX<ProcessGroupDO>()
                .likeIfPresent(ProcessGroupDO::getItems, items));
    }
}