package com.unis.finishedGrainSupervision.modular.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.unis.finishedGrainSupervision.modular.entity.*;
import com.unis.finishedGrainSupervision.modular.mapper.*;
import com.unis.finishedGrainSupervision.modular.param.DateCrkywCplcrkIdParam;
import com.unis.finishedGrainSupervision.modular.param.DateCrkywCplcrkPageParam;
import com.unis.finishedGrainSupervision.modular.service.DateCrkywCplcrkService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 成品粮出入库Service接口实现类
 *
 * @author ZeroLiYi
 * @date  2024/06/01 11:37
 **/
@Service
public class DateCrkywCplcrkServiceImpl implements DateCrkywCplcrkService {

    @Resource
    private DataCrkywCplckFlt001Mapper dataCckywCplckFlt001Mapper;

    @Resource
    private DataCrkywCplckDefaultMapper dataCrkywCplckDefaultMapper;

    @Resource
    private DataCrkywCplrkFlt001Mapper dataCrkywCplrkFlt001Mapper;

    @Resource
    private DataCrkywCplrkDefaultMapper dataCrkywCplrkDefaultMapper;
    @Resource
    private DateCrkywCplcrkMapper dateCrkywCplcrkMapper;

    @Override
    public IPage<Map<String, Object>> selectRkPage(DateCrkywCplcrkPageParam dateCrkywCplcrkPageParam) {
        //条形查询器
        QueryWrapper<DataCrkywCplrkDefault> queryWrapper = new QueryWrapper<>();

        if(StringUtils.isNotBlank(dateCrkywCplcrkPageParam.getRkbh())){
            queryWrapper.like("a.rkbh",dateCrkywCplcrkPageParam.getRkbh() );
        }
        if(StringUtils.isNotBlank(dateCrkywCplcrkPageParam.getSjjlspmc())){
            queryWrapper.like("a.sjjlspmcbh",dateCrkywCplcrkPageParam.getSjjlspmc() );
        }
        if (dateCrkywCplcrkPageParam.getYwsj() != null) {

            queryWrapper.eq("a.ywsj", dateCrkywCplcrkPageParam.getYwsj());
        }

        Page<DataCrkywCplrkDefault> p =new Page<>(dateCrkywCplcrkPageParam.getCurrent(),dateCrkywCplcrkPageParam.getSize());
        IPage<Map<String,Object>> page = dateCrkywCplcrkMapper.selectMaPage(p,queryWrapper);
        return page;
    }

    /**
     * 入库明细
     * @param dateCrkywCplcrkIdParam
     * @return
     */
    @Override
    public DataCrkywCplrkDefault selectRkdetails(DateCrkywCplcrkIdParam dateCrkywCplcrkIdParam) {
        DataCrkywCplrkDefault dataCrkywCplrkDefault=dataCrkywCplrkDefaultMapper.selectRkdetails(dateCrkywCplcrkIdParam);
        List<DataCrkywCplrkFlt001> dataCrkywCplrkFlt001List= dataCrkywCplrkFlt001Mapper.selectRkdetails(dateCrkywCplcrkIdParam);
        if(dataCrkywCplrkFlt001List!=null){
            dataCrkywCplrkDefault.setFltList(dataCrkywCplrkFlt001List);
        }
        return dataCrkywCplrkDefault;
    }

    @Override
    public IPage<Map<String, Object>> selectCkPage(DateCrkywCplcrkPageParam dateCrkywCplcrkPageParam) {
        //条形查询器
        QueryWrapper<DataCrkywCplckDefault> queryWrapper = new QueryWrapper<>();

        if(StringUtils.isNotBlank(dateCrkywCplcrkPageParam.getCkbh())){
            queryWrapper.like("a.ckbh",dateCrkywCplcrkPageParam.getCkbh() );
        }
        if(StringUtils.isNotBlank(dateCrkywCplcrkPageParam.getOrgName())){
            queryWrapper.like("oi.org_name",dateCrkywCplcrkPageParam.getOrgName() );
        }
        if (dateCrkywCplcrkPageParam.getYwsj() != null) {

            queryWrapper.eq("kc.modify_date", dateCrkywCplcrkPageParam.getYwsj());
        }

        Page<DataCrkywCplckDefault> p =new Page<>(dateCrkywCplcrkPageParam.getCurrent(),dateCrkywCplcrkPageParam.getSize());
        IPage<Map<String,Object>> page = dateCrkywCplcrkMapper.selectMaCkPage(p,queryWrapper);
        return page;
    }
    /**
     * 出库明细
     * @param dateCrkywCplcrkIdParam
     * @return
     */

    @Override
    public DataCrkywCplckDefault selectCkdetails(DateCrkywCplcrkIdParam dateCrkywCplcrkIdParam) {
        DataCrkywCplckDefault dataCrkywCplckDefault=dataCrkywCplckDefaultMapper.selectCkdetails(dateCrkywCplcrkIdParam);
        List<DataCrkywCplckFlt001> dataCrkywCplrkFlt001List= dataCckywCplckFlt001Mapper.selectCkdetails(dateCrkywCplcrkIdParam);
        if(dataCrkywCplrkFlt001List!=null){
            dataCrkywCplckDefault.setFltList(dataCrkywCplrkFlt001List);
        }
        return dataCrkywCplckDefault;
    }
}
