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

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
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.tbCoupon.dao.TbCouponDao;
import com.sqx.modules.tbCoupon.entity.TbCoupon;
import com.sqx.modules.tbCoupon.service.TbCouponService;
import com.sqx.modules.trainingCenter.dao.TrainingCenterDao;
import com.sqx.modules.trainingCenter.entity.TrainingCenter;
import com.sqx.modules.trainingCenter.service.TrainingCenterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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


@Service
public class TrainingCenterServiceImpl extends ServiceImpl<TrainingCenterDao, TrainingCenter> implements TrainingCenterService {

    @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 updateAdminTrainingCenter(TrainingCenter trainingCenter) {
        String format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
        baseMapper.updateAdminTrainingCenter(trainingCenter.getTrainingId(), trainingCenter.getTitle(), trainingCenter.getMessage(), trainingCenter.getDeleteFlag(), format, trainingCenter.getType());
        return Result.success();
    }

    @Override
    public Result addAdminTrainingCenter(TrainingCenter trainingCenter) {
        String format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
        baseMapper.addAdminTrainingCenter(trainingCenter.getTitle(), trainingCenter.getMessage(), trainingCenter.getDeleteFlag(), format, trainingCenter.getType());
        return Result.success();
    }


}
