package cn.exploring.engine.server.db.service;

import cn.exploring.engine.server.db.dao.StudentPointInfoMapper;
import cn.exploring.engine.server.db.domain.StudentPointInfo;
import cn.exploring.engine.server.db.domain.StudentPointInfoExample;
import org.springframework.stereotype.Service;

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

@Service
public class StudentPointService {

    @Resource
    StudentPointInfoMapper studentPointInfoMapper;

    /**
     * id 检索
     * @param idList
     * @return
     */
    public List<StudentPointInfo> selectPointInfo(List<Integer> idList) {
        StudentPointInfoExample example = new StudentPointInfoExample();
        StudentPointInfoExample.Criteria criteria = example.createCriteria();
        criteria.andDeletedEqualTo(false);
        if (idList != null && idList.size() > 0) {
            criteria.andIdIn(idList);
        }
        return studentPointInfoMapper.selectByExample(example);

    }

    public Object addPoint(StudentPointInfo studentPoint) {
        LocalDateTime now = LocalDateTime.now();
        studentPoint.setRecordTime(now);
        studentPoint.setUpdateTime(now);
        studentPoint.setAddTime(now);
        studentPoint.setDeleted(false);
        studentPointInfoMapper.insertSelective(studentPoint);
        return "add OK";
    }

    public Object updatePoint(StudentPointInfo studentPoint) {
        LocalDateTime now = LocalDateTime.now();
        studentPoint.setUpdateTime(now);
        studentPointInfoMapper.updateByPrimaryKey(studentPoint);
        return "update OK";
    }

    public Object batchDeleted(List<Integer> idList) {
        List<StudentPointInfo> studentPointInfoList = selectPointInfo(idList);
        studentPointInfoList.forEach(x -> {
            x.setDeleted(null);
            updatePoint(x);
        });
        return "batch deleted OK";
    }

}
