package com.dsk.system.service.impl;

import cn.hutool.core.bean.BeanException;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.dsk.common.annotation.DataScope;
import com.dsk.common.utils.SecurityUtils;
import com.dsk.system.domain.customer.CustomerFollowRecord;
import com.dsk.system.domain.customer.dto.CustomerFollowRecordSearchDto;
import com.dsk.system.domain.customer.vo.CustomerFollowRecordListVo;
import com.dsk.system.mapper.CustomerFollowRecordMapper;
import com.dsk.system.service.ICustomerFollowRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

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

/**
 * 客户跟进记录(CustomerFollowRecord)表服务实现类
 *
 * @author makejava
 * @since 2023-05-18 15:07:59
 */
@Slf4j
@Service
public class CustomerFollowRecordServiceImpl implements ICustomerFollowRecordService {

    @Resource
    private CustomerFollowRecordMapper baseMapper;

    @Override
    @DataScope(deptAlias = "d",userAlias = "u")
    public List<CustomerFollowRecordListVo> selectList(CustomerFollowRecordSearchDto dto) {
        if (ObjectUtils.isEmpty(dto.getCustomerId())) {
            dto.setUserId(SecurityUtils.getUserId());
        }
//        log.debug("dto.params.dataScope{}",dto.getParams().get("dataScope"));
        return baseMapper.selectAuthList(dto);
    }

    @Override
    public boolean add(CustomerFollowRecord followRecord) {
        if (ObjectUtils.isEmpty(followRecord.getContent())) throw new BeanException("跟进内容不能为空");
        if (ObjectUtils.isEmpty(followRecord.getCustomerId())) throw new BeanException("跟进客户不能为空");
        followRecord.setUserId(SecurityUtils.getUserId());
        return baseMapper.insert(followRecord) != 0;
    }

    @Override
    public boolean del(Long id) {
        return baseMapper.deleteById(id) != 0;
    }
}
