package com.dayou.service.impl;

import com.dayou.common.BaseEntity;
import com.dayou.dto.BusinessOpportunityDTO;
import com.dayou.entity.BusinessOpportunity;
import com.dayou.mapper.BusinessOpportunityMapper;
import com.dayou.service.IBusinessOpportunityService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dayou.utils.LoginContext;
import com.dayou.vo.BusinessOpportunityVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.dayou.utils.ExcelUtil;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
import java.util.ArrayList;
import org.springframework.transaction.annotation.Transactional;
import com.dayou.enums.BatchTaskTypeEnum;

/**
 * <p>
 * 商机 服务实现类
 * </p>
 *
 * @author wucl
 * @since 2023-01-10
 */
@Service
public class BusinessOpportunityServiceImpl extends ServiceImpl<BusinessOpportunityMapper, BusinessOpportunity> implements IBusinessOpportunityService {

    @Autowired
    private BusinessOpportunityMapper businessOpportunityMapper;

    @Override
    @SuppressWarnings("unchecked")
    public Page<BusinessOpportunityVO> selectPage(Page page, BusinessOpportunityVO businessOpportunity,String keyword){
        Page<BusinessOpportunityVO> result = businessOpportunityMapper.getPage(page,businessOpportunity,keyword);
        return result;
    }


    @Override
    public BusinessOpportunity detail(Long id){
        return this.getById(id);
    }

    @Override
    public Boolean add(BusinessOpportunity businessOpportunity){
        businessOpportunity.setUserId(LoginContext.getUserId());
        return  this.save(businessOpportunity);
    }

    @Override
    public Boolean update(BusinessOpportunity businessOpportunity){
        return  this.updateById(businessOpportunity);
    }

    @Override
    public Boolean delete(Long id){
        //逻辑删除
        return this.removeById(id);
    }

    @Override
    public Boolean changeManager(BusinessOpportunityDTO opportunity) {
        return this.update(new LambdaUpdateWrapper<BusinessOpportunity>().set(BusinessOpportunity::getUserId,opportunity.getUserId()).eq(BaseEntity::getId,opportunity.getId()));
    }
}
