package cn.com.ty.lift.batch.applet.service;

import cn.com.ty.lift.batch.applet.dao.mapper.ProjectMapper;
import cn.com.ty.lift.batch.applet.dao.model.Project;
import cn.com.ty.lift.common.constants.CommonEnum;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;

/**
 * @author bieao
 * @date 2020/2/10
 * @description 项目业务层
 */
@Service
@Slf4j
public class ProjectService extends ServiceImpl<ProjectMapper, Project> {

    /**
     * @return 项目列表
     * @description 查询项目列表
     * @date 2020/2/9 4:02 下午
     */
    public List<Project> queryProjectList() {
        LambdaQueryWrapper<Project> lambdaQueryWrapper = new QueryWrapper<Project>().lambda();
        lambdaQueryWrapper.lt(Project::getEndDate, LocalDate.now());
        lambdaQueryWrapper.ne(Project::getProjectStatus, CommonEnum.ProjectStatus.OVERDUE.getCode());
        return list(lambdaQueryWrapper);
    }

    /**
     * @param list 项目列表
     * @description 更新项目状态
     * @date 2020/2/10 4:16 下午
     */
    public void updateBatch(List<Project> list) {
        list.forEach(project -> project.setProjectStatus(CommonEnum.ProjectStatus.OVERDUE.getCode()));
        updateBatchById(list, list.size());
        log.info("批量更新项目状态" + list.size() + "条");
    }
}
