package com.muyu.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.util.StringUtil;
import com.muyu.system.domain.SysFirm;
import com.muyu.system.mapper.SysFirmMapper;
import com.muyu.system.service.ISysFirmService;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;

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

/**
 * 企业基础信息Service业务层处理
 *
 * @author muyu
 * @date 2024-09-18
 */
@Service
public class SysFirmServiceImpl
        extends ServiceImpl<SysFirmMapper, SysFirm>
        implements ISysFirmService {

    @Resource
    private SysFirmMapper sysFirmMapper;

    /**
     * 精确查询企业基础信息
     *
     * @param id 企业基础信息主键
     * @return 企业基础信息
     */
    @Override
    public SysFirm selectSysFirmById(Long id)
    {
        LambdaQueryWrapper<SysFirm> queryWrapper = new LambdaQueryWrapper<>();
        Assert.notNull(id, "id不可为空");
        queryWrapper.eq(SysFirm::getId, id);
        return this.getOne(queryWrapper);
    }


    /**
     * 查询企业基础信息列表
     *
     * @param sysFirm 企业基础信息
     * @return 企业基础信息
     */
    @Override
    public List<SysFirm> selectSysFirmList(SysFirm sysFirm) {
        LambdaQueryWrapper<SysFirm> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StringUtil.isNotEmpty(sysFirm.getFirmCreditCode()),
                SysFirm::getFirmCreditCode, sysFirm.getFirmCreditCode());
        queryWrapper.eq(StringUtil.isNotEmpty(sysFirm.getFirmCode()),
                SysFirm::getFirmCode, sysFirm.getFirmCode());
        queryWrapper.like(StringUtil.isNotEmpty(sysFirm.getFirmName()),
                SysFirm::getFirmName, sysFirm.getFirmName());
        List<SysFirm> sysFirmList = sysFirmMapper.selectSysFirmList(sysFirm);
        return sysFirmList;
    }

    /**
    * 唯一 判断
    * @param sysFirm 企业基础信息
     * @return 企业基础信息
    */
    @Override
    public Boolean checkIdUnique(SysFirm sysFirm) {
        LambdaQueryWrapper<SysFirm> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SysFirm::getFirmCreditCode, sysFirm.getFirmCreditCode());
        return this.count(queryWrapper) > 0;
    }



}
