package com.hzy.project.business.customer.service.impl;

import java.util.List;

import com.hzy.common.enums.EDelFlag;
import com.hzy.common.utils.DateUtils;
import com.hzy.common.utils.security.ShiroUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.hzy.project.business.customer.mapper.CustomerMapper;
import com.hzy.project.business.customer.domain.Customer;
import com.hzy.project.business.customer.service.ICustomerService;
import com.hzy.common.utils.text.Convert;

/**
 * 客户Service业务层处理
 * 
 * @author ruoyi
 * @date 2026-01-02
 */
@Service
public class CustomerServiceImpl implements ICustomerService 
{
    @Autowired
    private CustomerMapper customerMapper;

    /**
     * 查询客户
     * 
     * @param customerId 客户主键
     * @return 客户
     */
    @Override
    public Customer selectCustomerByCustomerId(Long customerId)
    {
        return customerMapper.selectCustomerByCustomerId(customerId);
    }

    /**
     * 查询客户列表
     * 
     * @param customer 客户
     * @return 客户
     */
    @Override
    public List<Customer> selectCustomerList(Customer customer)
    {
        return customerMapper.selectCustomerList(customer);
    }

    /**
     * 新增客户
     * 
     * @param customer 客户
     * @return 结果
     */
    @Override
    public int insertCustomer(Customer customer)
    {
        customer.setCreateBy(ShiroUtils.getLoginName());
        customer.setCreateTime(DateUtils.getNowDate());
        return customerMapper.insertCustomer(customer);
    }

    /**
     * 修改客户
     * 
     * @param customer 客户
     * @return 结果
     */
    @Override
    public int updateCustomer(Customer customer)
    {
        customer.setUpdateBy(ShiroUtils.getLoginName());
        customer.setUpdateTime(DateUtils.getNowDate());
        return customerMapper.updateCustomer(customer);
    }

    /**
     * 批量删除客户
     *
     * @param customerIds 需要删除的客户主键
     * @return 结果
     */
    @Override
    public int deleteCustomerByCustomerIds(String customerIds)
    {
        return customerMapper.deleteCustomerByCustomerIds(Convert.toStrArray(customerIds));
    }

    /**
     * 批量逻辑删除客户
     *
     * @param customerIds 需要删除的客户主键
     * @return 结果
     */
    @Override
    public int logicDelCustomerByCustomerIds(String customerIds)
    {
        String[] customerIdList = Convert.toStrArray(customerIds);
        int rtn = 0;
        for (String customerId : customerIdList) {
            Customer customer = new Customer();
            customer.setCustomerId(Long.valueOf(customerId));
            customer.setDelFlag(EDelFlag.YES.getVal());
            customer.setUpdateBy(ShiroUtils.getLoginName());
            customer.setUpdateTime(DateUtils.getNowDate());
            rtn += customerMapper.updateCustomer(customer);
        }
        return rtn;
    }

    /**
     * 删除客户信息
     * 
     * @param customerId 客户主键
     * @return 结果
     */
    @Override
    public int deleteCustomerByCustomerId(Long customerId)
    {
        return customerMapper.deleteCustomerByCustomerId(customerId);
    }
}
