/*
 * Copyright [2022] [https://www.xiaonuo.vip]
 *
 * Snowy采用APACHE LICENSE 2.0开源协议，您在使用过程中，需要注意以下几点：
 *
 * 1.请不要删除和修改根目录下的LICENSE文件。
 * 2.请不要删除和修改Snowy源码头部的版权声明。
 * 3.本项目代码可免费商业使用，商业使用请保留源码和相关描述文件的项目出处，作者声明等。
 * 4.分发源码时候，请注明软件出处 https://www.xiaonuo.vip
 * 5.不可二次分发开源参与同类竞品，如有想法可联系团队xiaonuobase@qq.com商议合作。
 * 6.若您的项目无法满足以上几点，需要更多功能代码，获取Snowy商业授权许可，请在官网购买授权，地址为 https://www.xiaonuo.vip
 */

package com.unis.statisticalAnalysis.modular.kczl.service.impl;


import cn.hutool.core.util.ObjectUtil;
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.statisticalAnalysis.modular.kczl.entity.BusinessQcQualityInspection;
import com.unis.statisticalAnalysis.modular.kczl.mapper.KczlMapper;
import com.unis.statisticalAnalysis.modular.kczl.param.TjfxPageParam;
import com.unis.statisticalAnalysis.modular.kczl.service.KczlService;
import org.springframework.stereotype.Service;

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


/**
 * 维保管理
 *
 * @author shine
 * @date  2024/05/30 17:34
 **/

@Service
public class KczlServiceImpl<KczlServiceMapper> implements KczlService {

    @Resource
    private KczlMapper kczlMapper;

    @Override
    public IPage<List<Map<String,Object>>> findPage(TjfxPageParam tjfxPageParam) {
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("orgName",tjfxPageParam.getOrgName());
        map.put("city",tjfxPageParam.getCity());
        map.put("designCapacity",tjfxPageParam.getDesignCapacity());

        return kczlMapper.findPage(new Page<>(tjfxPageParam.getCurrent(), tjfxPageParam.getSize()), map);
    }

   /* public IPage<Map<String, Object>> findPage(OrgInfoPageParam orgInfoPageParam) {

        QueryWrapper<OrgInfo> queryWrapper = new QueryWrapper<>();
        //分页相关
        if (orgInfoPageParam.getOrgName() != null) {
            queryWrapper.like("a.org_name", orgInfoPageParam.getOrgName());
        }

        Page<OrgInfo> p = new Page<>(orgInfoPageParam.getCurrent(), orgInfoPageParam.getSize());

        IPage<Map<String, Object>> page = orgInfoMapper.findPage(p, queryWrapper);
        return page;

    }*/


    @Override
    public Page<Map<String,Object>> detailsPage(TjfxPageParam tjfxPageParam) {
        QueryWrapper<BusinessQcQualityInspection> queryWrapper = new QueryWrapper<>();
        //分页相关
        if (tjfxPageParam.getOrgId() != null) {
            queryWrapper.eq("qqi.org_id", tjfxPageParam.getOrgId());
        }
        /*if (tjfxPageParam.getLsdj() != null) {
            queryWrapper.eq("qqi.grain_grade_id", tjfxPageParam.getLsdj());
        }
        if (tjfxPageParam.getLsxz() != null) {
            queryWrapper.eq("qqi.grain_nature_id", tjfxPageParam.getLsxz());
        }
        if (tjfxPageParam.getLspz() != null) {
            queryWrapper.eq("qqi.grain_variety_id", tjfxPageParam.getLspz());
        }
        if (tjfxPageParam.getCfmc() != null) {
            queryWrapper.like("bs.storehouse_name", tjfxPageParam.getCfmc());
        }*/
        if (tjfxPageParam.getOrgName() != null) {
            queryWrapper.like("oi.org_name", tjfxPageParam.getOrgName());
        }
        if (tjfxPageParam.getLsdjName() != null) {
            queryWrapper.like("be2.enumname", tjfxPageParam.getLsdjName());
        }
        if (tjfxPageParam.getLsxzName() != null) {
            queryWrapper.like("be1.enumname", tjfxPageParam.getLsxzName());
        }
        if (tjfxPageParam.getLspzName() != null) {
            queryWrapper.like("be.enumname", tjfxPageParam.getLspzName());
        }
        if (tjfxPageParam.getCfmc() != null) {
            queryWrapper.like("bs.storehouse_name", tjfxPageParam.getCfmc());
        }

        Page<BusinessQcQualityInspection> p = new Page<>(tjfxPageParam.getCurrent(), tjfxPageParam.getSize());

        Page<Map<String,Object>> page = kczlMapper.detailsPage(p, queryWrapper);
        return page;
    }

    @Override
    public BusinessQcQualityInspection getByMasterId(String id) {
        // id查询主表数据
        BusinessQcQualityInspection masterParam = kczlMapper.selectZjByPrimaryKey(id);
        if(ObjectUtil.isNotNull(masterParam)){
            masterParam.setItem(kczlMapper.selectZjMXByMainKey(id));
        }
        return masterParam;
    }

   /* @Override
    public IPage<Map<String, Object>> findPage(DevicePageParam devicePageParam) {
        QueryWrapper<Devicerepair> queryWrapper = new QueryWrapper<>();
        //分页相关
        if (devicePageParam.getOrgName() != null) {
            queryWrapper.like("b.org_name", devicePageParam.getOrgName());
        }
        if (devicePageParam.getDeviceName() != null) {
            queryWrapper.like("a.device_name", devicePageParam.getDeviceName());
        }

        Page<Devicerepair> p = new Page<>(devicePageParam.getCurrent(), devicePageParam.getSize());

        IPage<Map<String, Object>> page = deviceMapper.findPage(p, queryWrapper);

        return page;
    }*/

}

