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

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.cf.imes.framework.common.pojo.PageResult;
import com.cf.imes.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.cf.imes.framework.mybatis.core.mapper.BaseMapperX;
import com.cf.imes.module.manage.controller.admin.plate.vo.remain.RemainPlatePageReqVO;
import com.cf.imes.module.manage.dal.dataobject.remainplaten.RemainPlateDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.Set;

/**
 * 生产单余料板表 order_remain_plate_{N} Mapper
 *
 * @author 晨丰科技
 */
@Mapper
public interface RemainPlateMapper extends BaseMapperX<RemainPlateDO> {

    default PageResult<RemainPlateDO> selectPage(RemainPlatePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<RemainPlateDO>()
                .eqIfPresent(RemainPlateDO::getPlanId, reqVO.getPlanId())
                .eqIfPresent(RemainPlateDO::getInitPlanId, reqVO.getInitPlanId())
                .eqIfPresent(RemainPlateDO::getStatus, reqVO.getStatus())
                .eqIfPresent(RemainPlateDO::getGoodsId, reqVO.getGoodsId())
                .eqIfPresent(RemainPlateDO::getIsCutting, reqVO.getIsCutting())
                .likeIfPresent(RemainPlateDO::getName, reqVO.getName())
                .eqIfPresent(RemainPlateDO::getMaterial, reqVO.getMaterial())
                .eqIfPresent(RemainPlateDO::getColor, reqVO.getColor())
                .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::getUseType, reqVO.getUseType())
                .eqIfPresent(RemainPlateDO::getOrganId, reqVO.getOrganId())
                .eqIfPresent(RemainPlateDO::getOutLineJson, reqVO.getOutLineJson())
                .betweenIfPresent(RemainPlateDO::getWidth, reqVO.getWidth())
                .betweenIfPresent(RemainPlateDO::getLength, reqVO.getLength())
                .betweenIfPresent(RemainPlateDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(RemainPlateDO::getId));
    }

    // 批量修改状态
    default void updateRemainPlateStatus(Set<Long> ids, Integer status, Integer useType,Long organId,Long planId) {
        update(new UpdateWrapper<RemainPlateDO>()
                .set("status", status)
                .set("use_type", useType)
                .set("plan_id",planId)
                .eq("organ_id",organId)
                .in("id", ids));
    }
}