package com.yijia.customer.service.impl;


import com.yijia.common.core.domain.entity.SysDept;
import com.yijia.common.core.domain.model.LoginUser;
import com.yijia.common.utils.SecurityUtils;
import com.yijia.customer.domain.CustomerManage;
import com.yijia.customer.mapper.CustomerManageMapper;
import com.yijia.customer.service.ICustomerManageService;
import com.yijia.system.mapper.SysDeptMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 客户管理Service业务层处理
 *
 * @author yijia
 * @date 2020-12-21
 */
@Service
public class CustomerManageServiceImpl implements ICustomerManageService
{
    @Autowired
    private CustomerManageMapper customerManageMapper;
    /**
     * 查询客户管理
     *
     * @param id 客户管理ID
     * @return 客户管理
     */
    @Override
    public CustomerManage selectCustomerManageById(Long id)
    {
        return customerManageMapper.selectCustomerManageById(id);
    }

    /**
     * 查询客户管理列表
     *
     * @param customerManage 客户管理
     * @return 客户管理
     */
    @Override
    public List<CustomerManage> selectCustomerManageList(CustomerManage customerManage)
    {
        return customerManageMapper.selectCustomerManageList(customerManage);
    }

    /**
     * 新增客户管理
     *
     * @param customerManage 客户管理
     * @return 结果
     */
    @Override
    public int insertCustomerManage(CustomerManage customerManage)
    {
        return customerManageMapper.insertCustomerManage(customerManage);
    }

    /**
     * 修改客户管理
     *
     * @param customerManage 客户管理
     * @return 结果
     */
    @Override
    public int updateCustomerManage(CustomerManage customerManage)
    {
        return customerManageMapper.updateCustomerManage(customerManage);
    }

    /**
     * 批量删除客户管理
     *
     * @param ids 需要删除的客户管理ID
     * @return 结果
     */
    @Override
    public int deleteCustomerManageByIds(Long[] ids)
    {
        return customerManageMapper.deleteCustomerManageByIds(ids);
    }

    /**
     * 删除客户管理信息
     *
     * @param id 客户管理ID
     * @return 结果
     */
    @Override
    public int deleteCustomerManageById(Long id)
    {
        return customerManageMapper.deleteCustomerManageById(id);
    }

    /**
     * 客户信息查询
     * @param customerManage
     * @return
     */
    @Override
    public List<CustomerManage> selectCustomerManage(CustomerManage customerManage) {
//        List<CustomerManage> list =new ArrayList<>();
//        LoginUser currentUser = SecurityUtils.getLoginUser();
//        SysDept dept = deptMapper.selectDeptById(currentUser.getUser().getDeptId());
//        if(dept!=null &&dept.getJiBie()!=null  && dept.getJiBie()==1 ){
//            if(dept.getIntegralRuleFlag()!=null &&dept.getIntegralRuleFlag().equals("1")&&dept.getCardRuleFlag().equals("1") ){
//
//            }else if(dept.getIntegralRuleFlag()!=null &&dept.getIntegralRuleFlag().equals("0") && dept.getCardRuleFlag().equals("1") ){
//
//            }else if(dept.getIntegralRuleFlag()!=null &&dept.getIntegralRuleFlag().equals("1") && dept.getCardRuleFlag().equals("0") ){
//
//            }else{
//
//            }
//        }else if(dept!=null && dept.getJiBie()!=null  && dept.getJiBie()==2){
//            SysDept sysDept  = deptMapper.selectDeptById(dept.getParentId());
//            if(sysDept.getIntegralRuleFlag()!=null &&sysDept.getIntegralRuleFlag().equals("1")&&sysDept.getCardRuleFlag().equals("1") ){
//                list = customerManageMapper.selectCustomerManageInteralrule(customerManage);
//            }else if(sysDept.getIntegralRuleFlag()!=null &&sysDept.getIntegralRuleFlag().equals("0") && sysDept.getCardRuleFlag().equals("1") ){
//
//            }else if(sysDept.getIntegralRuleFlag()!=null &&sysDept.getIntegralRuleFlag().equals("1") && sysDept.getCardRuleFlag().equals("0") ){
//
//                list = customerManageMapper.selectCustomerManageInteralrule(customerManage);
//            }else{
//                customerManage.setStationId(dept.getDeptId());
//                list = customerManageMapper.selectCustomerManage(customerManage);
//            }
//        }else if(dept!=null && dept.getJiBie()!=null  && dept.getJiBie()==0) {
//
//        }

        return customerManageMapper.selectCustomerManage(customerManage);
    }

    @Override
    public List<CustomerManage> selectCustomerManagePage(CustomerManage customerManage) {
        return customerManageMapper.selectCustomerManagePage(customerManage);
    }
}
