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

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sqx.common.utils.DateUtils;
import com.sqx.common.utils.PageUtils;
import com.sqx.common.utils.Result;
import com.sqx.modules.appeal.dao.AppealDao;
import com.sqx.modules.appeal.entity.Appeal;
import com.sqx.modules.appeal.service.AppealService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.Map;

@Slf4j
@Service
public class AppealServiceImpl extends ServiceImpl<AppealDao, Appeal> implements AppealService {
    @Resource
    private AppealDao appealDao;


    @Override
    public PageUtils getAppealPage(Integer page, Integer limit, Long userId, Appeal appeal, String startTime, String endTime) {
        Page<Map<String, Object>> pages = new Page<>(page, limit);
        return new PageUtils(appealDao.getAppealPage(pages,userId, appeal,startTime,endTime));
    }

    @Override
    public Result insertAppeal(Appeal appeal) {
        appeal.setCreateTime(DateUtils.format(new Date()));
        appealDao.insert(appeal);
        return Result.success();
    }

    @Override
    public Result updateAppeal(Appeal appeal) {
        baseMapper.updateById(appeal);
        return Result.success();
    }

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