package com.dsk.biz.service.impl;

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

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

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

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

    @Override
    public TableDataInfo<BusinessFollowRecord> selectBusinessFollowRecordList(BusinessIdDto dto, PageQuery pageQuery)
    {
        return TableDataInfo.build(businessFollowRecordMapper.selectBusinessFollowRecordList(pageQuery.build(),dto));
    }

    @Override
//    @DataScope(userAlias = "u",deptAlias = "d")
    public TableDataInfo<BusinessFollowRecord> allFollow(BusinessListDto dto, PageQuery pageQuery) {
        //userId不传值，就查询全部
//        if (dto.getUserId() == null) {
//            Long deptId = SecurityUtils.getLoginUser().getDeptId();
//            if (deptId == null) throw new BaseException("请登录");
//            dto.setDeptId(deptId.intValue());
//        }
        return TableDataInfo.build(businessFollowRecordMapper.allFollow(pageQuery.build(),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);
    }
}
