package com.ruoyi.web.v2.v1.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.web.v2.v1.model.JsTraining;
import com.ruoyi.web.v2.v1.mapper.JsTrainingMapper;
import com.ruoyi.web.v2.v1.service.IJsTrainingService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import static com.ruoyi.common.core.domain.AjaxResult.success;

/**
 * <p>
 * v2.0员工培训 服务实现类
 * </p>
 *
 * @author author
 * @since 2025-06-19
 */
@Service
public class JsTrainingServiceImpl extends ServiceImpl<JsTrainingMapper, JsTraining> implements IJsTrainingService {

    @Autowired
    private JsTrainingMapper jsTrainingMapper;

    @Override
    public AjaxResult add(JsTraining jsTraining) {
        jsTrainingMapper.insert(jsTraining);
        return success();
    }

    @Override
    public AjaxResult edit(JsTraining jsTraining) {
        jsTrainingMapper.updateById(jsTraining);
        return success();
    }

    @Override
    public AjaxResult delete(String ids) {
        String[] split = ids.split(",");
        for (String s : split) {
            jsTrainingMapper.deleteById(s);
        }
        return success();
    }

    @Override
    public AjaxResult page(Integer pageNum, Integer pageSize, String startTime, String endTime) {
        Page<JsTraining> page = new Page<>(pageNum, pageSize);
        QueryWrapper<JsTraining> queryWrapper = new QueryWrapper<>();
        if ("".equals(startTime) || null == startTime) {

        } else {
            queryWrapper.between("training_time", startTime, endTime);
        }

        queryWrapper.orderByDesc("training_time");
        return success(jsTrainingMapper.selectPage(page, queryWrapper));
    }

    @Override
    public AjaxResult listAll() {
        return null;
    }
}
