package com.cf.imes.module.executor.dal.mysql.remainplaten;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
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.executor.controller.admin.plan.saveOptimize.OptimizeRemainPlate;
import com.cf.imes.module.executor.controller.admin.remainplate.vo.RemainPlatePageReqVO;
import com.cf.imes.module.executor.dal.dataobject.processStep.ProcessStepDO;
import com.cf.imes.module.executor.dal.dataobject.remainplaten.RemainPlateDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.Collection;
import java.util.List;

import static com.cf.imes.framework.security.core.util.SecurityFrameworkUtils.getUserOrganId;

@Mapper
public interface RemainPlateMapper extends BaseMapperX<RemainPlateDO> {

    default PageResult<RemainPlateDO> selectPage(RemainPlatePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<RemainPlateDO>()
                .eq(RemainPlateDO::getOrganId,getUserOrganId())
                .eqIfPresent(RemainPlateDO::getPlanId, reqVO.getPlanId())
                .eqIfPresent(RemainPlateDO::getInitPlanId, reqVO.getInitPlanId())
                .eqIfPresent(RemainPlateDO::getStatus, reqVO.getStatus())
                .eqIfPresent(RemainPlateDO::getGoodsId, reqVO.getGoodsId())
                .likeIfPresent(RemainPlateDO::getName, reqVO.getName())
                .eqIfPresent(RemainPlateDO::getMaterial, reqVO.getMaterial())
                .eqIfPresent(RemainPlateDO::getColor, reqVO.getColor())
                .eqIfPresent(RemainPlateDO::getWidth, reqVO.getWidth())
                .eqIfPresent(RemainPlateDO::getLength, reqVO.getLength())
                .eqIfPresent(RemainPlateDO::getThickness, reqVO.getThickness())
                .eqIfPresent(RemainPlateDO::getBrand, reqVO.getBrand())
                .eqIfPresent(RemainPlateDO::getPlaceStyle, reqVO.getPlaceStyle())
                .eqIfPresent(RemainPlateDO::getStore, reqVO.getStore())
                .eqIfPresent(RemainPlateDO::getCount, reqVO.getCount())
                .eqIfPresent(RemainPlateDO::getRemark, reqVO.getRemark())
                .eqIfPresent(RemainPlateDO::getOutLineJson, reqVO.getOutline())
                .betweenIfPresent(RemainPlateDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(RemainPlateDO::getId));
    }


    default List<RemainPlateDO> selectByPlanId(Long planId, Long userOrganId) {
        return selectList( new LambdaQueryWrapperX<RemainPlateDO>()
                .eq(RemainPlateDO::getOrganId, userOrganId)
                .eq(RemainPlateDO::getPlanId, planId));


    }



    // 批量修改删除状态
    default int updateOrderDeleted(Collection<Long> ids, Integer deleted, Long organId) {
        return update(new LambdaUpdateWrapper<RemainPlateDO>()
                .set(RemainPlateDO::getDeleted, deleted)
                .in(RemainPlateDO::getId, ids)
                .eq(RemainPlateDO::getOrganId, organId));
    }
}
