package com.sqx.modules.errand.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sqx.common.utils.PageUtils;
import com.sqx.common.utils.Result;
import com.sqx.modules.errand.dao.AdminTrainingCenterDao;
import com.sqx.modules.errand.dao.UserInfoDao;
import com.sqx.modules.errand.entity.TbIndent;
import com.sqx.modules.errand.entity.TrainingCenter;
import com.sqx.modules.errand.service.AdminTrainingCenterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;

@Service
public class AdminTrainingCenterServiceImpl extends ServiceImpl<AdminTrainingCenterDao, TrainingCenter> implements AdminTrainingCenterService {

    @Autowired
    private UserInfoDao userInfoDao;
    @Autowired
    private AdminTrainingCenterDao adminTrainingCenterDao;

    @Override
    public Result adminTrainingCenter(Integer page, Integer limit, String title, Integer type) {
        Page<TrainingCenter> pages=new Page<>(page,limit);
        PageUtils pageUtils = new PageUtils(baseMapper.adminTrainingCenter(pages, title, type));
        return Result.success().put("data", pageUtils);
    }

    @Override
    public Result TrainingCenter(Long id) {
        TrainingCenter trainingCenter = userInfoDao.TrainingCenter(id);
        return Result.success().put("data", trainingCenter);
    }

    @Override
    public Result insertAdminTrainingCenter(TrainingCenter trainingCenter) {
        String format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
        trainingCenter.setCreateTime(format);
        baseMapper.insert(trainingCenter);
        return Result.success();
    }

    @Override
    public Result updateAdminTrainingCenter(TrainingCenter trainingCenter) {
        String format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
        trainingCenter.setUpdateTime(format);
        baseMapper.updateById(trainingCenter);
        return Result.success();
    }

    @Override
    public Result deleteAdminTrainingCenter(Long id) {
        baseMapper.deleteById(id);
        return Result.success();
    }

}
