package com.yanzhu.jh.project.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.yanzhu.jh.project.domain.vo.MajorPlanExport;
import com.yanzhu.jh.project.domain.vo.UrbanPlanExport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yanzhu.jh.project.mapper.SurProjectPlanMapper;
import com.yanzhu.jh.project.domain.SurProjectPlan;
import com.yanzhu.jh.project.service.ISurProjectPlanService;
import com.ruoyi.common.utils.SecurityUtils;
/**
 * 项目跟进计划Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-09-07
 */
@Service
public class SurProjectPlanServiceImpl implements ISurProjectPlanService 
{
    @Autowired
    private SurProjectPlanMapper surProjectPlanMapper;

    /**
     * 查询项目跟进计划
     * 
     * @param id 项目跟进计划主键
     * @return 项目跟进计划
     */
    @Override
    public SurProjectPlan selectSurProjectPlanById(Long id)
    {
        return surProjectPlanMapper.selectSurProjectPlanById(id);
    }

    /**
     * 查询项目跟进计划列表
     * 
     * @param surProjectPlan 项目跟进计划
     * @return 项目跟进计划
     */
    @Override
    public List<SurProjectPlan> selectSurProjectPlanList(SurProjectPlan surProjectPlan)
    {
        return surProjectPlanMapper.selectSurProjectPlanList(surProjectPlan);
    }

    /**
     * 新增项目跟进计划
     * 
     * @param surProjectPlan 项目跟进计划
     * @return 结果
     */
    @Override
    public int insertSurProjectPlan(SurProjectPlan surProjectPlan)
    {
        surProjectPlan.setCreateBy(SecurityUtils.getUsername());
        surProjectPlan.setCreateTime(DateUtils.getNowDate());
        return surProjectPlanMapper.insertSurProjectPlan(surProjectPlan);
    }

    /**
     * 修改项目跟进计划
     * 
     * @param surProjectPlan 项目跟进计划
     * @return 结果
     */
    @Override
    public int updateSurProjectPlan(SurProjectPlan surProjectPlan)
    {
        surProjectPlan.setUpdateBy(SecurityUtils.getUsername());
        surProjectPlan.setUpdateTime(DateUtils.getNowDate());
        return surProjectPlanMapper.updateSurProjectPlan(surProjectPlan);
    }

    /**
     * 批量删除项目跟进计划
     * 
     * @param ids 需要删除的项目跟进计划主键
     * @return 结果
     */
    @Override
    public int deleteSurProjectPlanByIds(Long[] ids)
    {
        return surProjectPlanMapper.deleteSurProjectPlanByIds(ids);
    }

    /**
     * 删除项目跟进计划信息
     * 
     * @param id 项目跟进计划主键
     * @return 结果
     */
    @Override
    public int deleteSurProjectPlanById(Long id)
    {
        return surProjectPlanMapper.deleteSurProjectPlanById(id);
    }

    @Override
    public int importUrbanPlan(List<UrbanPlanExport> list) {
        SurProjectPlan where=new SurProjectPlan();
        where.setPlanType(0l);
        List<SurProjectPlan> oldList=selectSurProjectPlanList(where);
        int i=0;
        for(;i<list.size();i++){
            UrbanPlanExport item=list.get(i);
            if(i<oldList.size()){
                SurProjectPlan it=oldList.get(i);
                item.setValue(it);
                it.setPlanType(0l);
                this.updateSurProjectPlan(it);
            }else{
                SurProjectPlan it=item.toPlan();
                it.setPlanType(0l);
                this.insertSurProjectPlan(it);
            }
        }
        for(;i<oldList.size();i++){
            SurProjectPlan it=oldList.get(i);
            it.setPlanType(0l);
            it.setIsDel(1l);
            this.updateSurProjectPlan(it);
        }
        return list.size();
    }

    @Override
    public int importMajorPlan(List<MajorPlanExport> list) {
        SurProjectPlan where=new SurProjectPlan();
        where.setPlanType(1l);
        List<SurProjectPlan> oldList=selectSurProjectPlanList(where);
        int i=0;
        for(;i<list.size();i++){
            MajorPlanExport item=list.get(i);
            if(i<oldList.size()){
                SurProjectPlan it=oldList.get(i);
                item.setValue(it);
                it.setPlanType(1l);
                this.updateSurProjectPlan(it);
            }else{
                SurProjectPlan it=item.toPlan();
                it.setPlanType(1l);
                this.insertSurProjectPlan(it);
            }
        }
        for(;i<oldList.size();i++){
            SurProjectPlan it=oldList.get(i);
            it.setPlanType(1l);
            it.setIsDel(1l);
            this.updateSurProjectPlan(it);
        }
        return 0;
    }

    @Override
    public List<SurProjectPlan> selectSurProjectPlanListTop3() {
        return surProjectPlanMapper.selectSurProjectPlanListTop3();
    }
}
