package com.muyu.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.muyu.common.core.utils.StringUtils;
import com.muyu.common.system.domain.SysEnt;
import com.muyu.system.domain.req.EntListReq;
import com.muyu.system.domain.resp.EntResp;
import com.muyu.system.mapper.SysEntMapper;
import com.muyu.system.service.SysEntService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: zi run
 * @Date 2024/9/26 0:15
 * @Description 企业管理业务实现层
 */
@Service
@RequiredArgsConstructor
public class SysEntServiceImpl extends ServiceImpl<SysEntMapper, SysEnt> implements SysEntService {

    /**
     * 企业管理持久层
     */
    private final SysEntMapper sysEntMapper;

    /**
     * 查询企业信息列表
     * @param entListReq 企业列表请求对象
     * @return 返回结果
     */
    @Override
    public List<EntResp> selectList(EntListReq entListReq) {
        LambdaQueryWrapper<SysEnt> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(
                StringUtils.isNotEmpty(entListReq.getEntName()),
                SysEnt::getName, entListReq.getEntName()
        );
        queryWrapper.like(
                StringUtils.isNotEmpty(entListReq.getLeader()),
                SysEnt::getLeader, entListReq.getLeader()
        );
        queryWrapper.like(
                StringUtils.isNotEmpty(entListReq.getPhone()),
                SysEnt::getPhone, entListReq.getPhone()
        );
        queryWrapper.like(
                StringUtils.isNotEmpty(entListReq.getEmail()),
                SysEnt::getEmail, entListReq.getEmail()
        );
        queryWrapper.eq(
                StringUtils.isNotEmpty(entListReq.getEntCode()),
                SysEnt::getEntCode, entListReq.getEntCode()

        );
        List<SysEnt> sysEntList = this.list(queryWrapper);

        return sysEntList.stream()
                .map(EntResp::entBuild)
                .toList();
    }
}
