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

import java.util.*;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.cf.imes.framework.common.pojo.PageResult;
import com.cf.imes.framework.common.util.object.BeanUtils;
import com.cf.imes.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.cf.imes.framework.mybatis.core.mapper.BaseMapperX;
import com.cf.imes.module.executor.controller.admin.rawgoods.vo.RawGoodsImportRespVO;
import com.cf.imes.module.executor.controller.admin.rawgoods.vo.RawGoodsPageReqVO;
import com.cf.imes.module.executor.controller.admin.rawgoods.vo.RawGoodsSaveReqVO;
import com.cf.imes.module.executor.dal.dataobject.plate.PlateDO;
import com.cf.imes.module.executor.dal.dataobject.rawgoods.RawGoodsDO;
import org.apache.ibatis.annotations.Mapper;

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

/**
 * 生产单设计商品表 order_raw_goods_{N} Mapper
 *
 * @author 晨丰科技
 */
@Mapper
public interface RawGoodsMapper extends BaseMapperX<RawGoodsDO> {

    default PageResult<RawGoodsDO> selectPage(RawGoodsPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<RawGoodsDO>()
                .eq(RawGoodsDO::getOrganId,getUserOrganId())
                .eqIfPresent(RawGoodsDO::getOrderId, reqVO.getOrderId())
                .eqIfPresent(RawGoodsDO::getRawGoodsId, reqVO.getRawGoodsId())
                .likeIfPresent(RawGoodsDO::getGoodsName, reqVO.getGoodsName())
                .eqIfPresent(RawGoodsDO::getMaterial, reqVO.getMaterial())
                .eqIfPresent(RawGoodsDO::getColor, reqVO.getColor())
                .eqIfPresent(RawGoodsDO::getThickness, reqVO.getThickness())
                .eqIfPresent(RawGoodsDO::getPrice, reqVO.getPrice())
                .eqIfPresent(RawGoodsDO::getBrand, reqVO.getBrand())
                .eqIfPresent(RawGoodsDO::getSpec, reqVO.getSpec())
                .betweenIfPresent(RawGoodsDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(RawGoodsDO::getId));
    }


    // 单个修改删除状态
    default int updateOrderDeleted(Long id, Integer deleted, Long organId) {
        LambdaUpdateWrapper<RawGoodsDO> wrapper = new LambdaUpdateWrapper<RawGoodsDO>()
                .set(RawGoodsDO::getDeleted, deleted)
                .eq(RawGoodsDO::getOrderId, id)
                .eq(RawGoodsDO::getOrganId, organId);
        if (deleted == 0)
            wrapper.eq(RawGoodsDO::getDeleted, 1);
        return update(wrapper);
    }
}