package com.dsk.system.service.impl;

import com.dsk.common.core.domain.entity.BusinessFollowRecord;
import com.dsk.common.utils.DateUtils;
import com.dsk.system.domain.BusinessIdDto;
import com.dsk.system.domain.BusinessListDto;
import com.dsk.system.domain.vo.BusinessListVo;
import com.dsk.system.mapper.BusinessFollowRecordMapper;
import com.dsk.system.service.IBusinessFollowRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 项目跟进记录Service业务层处理
 *
 * @author lxl
 * @date 2023-05-17
 */
@Service
public class BusinessFollowRecordServiceImpl implements IBusinessFollowRecordService
{
    @Autowired
    private BusinessFollowRecordMapper businessFollowRecordMapper;

    /**
     * 查询项目跟进记录
     *
     * @param id 项目跟进记录主键
     * @return 项目跟进记录
     */
    @Override
    public BusinessFollowRecord selectBusinessFollowRecordById(Long id)
    {
        return businessFollowRecordMapper.selectBusinessFollowRecordById(id);
    }

    @Override
    public List<BusinessFollowRecord> selectBusinessFollowRecordList(BusinessIdDto businessId)
    {
        return businessFollowRecordMapper.selectBusinessFollowRecordList(businessId);
    }

    @Override
    public List<BusinessFollowRecord> allFollow(BusinessListDto dto) {
        //userId不传值，就查询全部
//        if (dto.getUserId() == null) {
//            Long deptId = SecurityUtils.getLoginUser().getDeptId();
//            if (deptId == null) throw new BaseException("请登录");
//            dto.setDeptId(deptId.intValue());
//        }
        return businessFollowRecordMapper.allFollow(dto);
    }

    @Override
    public List<BusinessFollowRecord> businessFollowRecordPaging(BusinessFollowRecord businessFollowRecord) {
        return businessFollowRecordMapper.businessFollowRecordPaging(businessFollowRecord);
    }

    /**
     * 新增项目跟进记录
     *
     * @param businessFollowRecord 项目跟进记录
     * @return 结果
     */
    @Override
    @Transactional
    public int insertBusinessFollowRecord(BusinessFollowRecord businessFollowRecord)
    {
        return businessFollowRecordMapper.insertBusinessFollowRecord(businessFollowRecord);
    }

    @Override
    public List<BusinessListVo> selectRelateProject(Integer userId) {
        return businessFollowRecordMapper.selectRelateProject(userId);
    }

    @Override
    public List<String> selectRelateCompany(Integer userId) {
        return businessFollowRecordMapper.selectRelateCompany(userId);
    }

    /**
     * 修改项目跟进记录
     *
     * @param businessFollowRecord 项目跟进记录
     * @return 结果
     */
    @Override
    public int updateBusinessFollowRecord(BusinessFollowRecord businessFollowRecord)
    {
        businessFollowRecord.setUpdateTime(DateUtils.getNowDate());
        return businessFollowRecordMapper.updateBusinessFollowRecord(businessFollowRecord);
    }

    /**
     * 批量删除项目跟进记录
     *
     * @param ids 需要删除的项目跟进记录主键
     * @return 结果
     */
    @Override
    @Transactional
    public int deleteBusinessFollowRecordByIds(Long[] ids)
    {
        return businessFollowRecordMapper.deleteBusinessFollowRecordByIds(ids);
    }

    /**
     * 删除项目跟进记录信息
     *
     * @param id 项目跟进记录主键
     * @return 结果
     */
    @Override
    public int deleteBusinessFollowRecordById(Long id)
    {
        return businessFollowRecordMapper.deleteBusinessFollowRecordById(id);
    }
}
