package com.dsk.biz.service.impl;

import cn.hutool.core.bean.BeanException;
import com.dsk.biz.domain.CustomerFollowRecord;
import com.dsk.biz.domain.bo.CustomerFollowRecordSearchDto;
import com.dsk.biz.domain.vo.CustomerFollowRecordListVo;
import com.dsk.biz.mapper.CustomerFollowRecordMapper;
import com.dsk.biz.service.ICustomerFollowRecordService;
import com.dsk.common.core.domain.PageQuery;
import com.dsk.common.core.page.TableDataInfo;
import com.dsk.common.helper.LoginHelper;
import com.google.api.client.util.SecurityUtils;
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 TableDataInfo<CustomerFollowRecordListVo> selectList(CustomerFollowRecordSearchDto dto, PageQuery pageQuery) {
        if (ObjectUtils.isEmpty(dto.getCustomerId())) {
            dto.setUserId(LoginHelper.getUserId());
        }
//        log.debug("dto.params.dataScope{}",dto.getParams().get("dataScope"));
        return TableDataInfo.build(baseMapper.selectAuthList(pageQuery.build(), 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(LoginHelper.getUserId());
        return baseMapper.insert(followRecord) != 0;
    }

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