package com.sptg.permissions.biz.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.sptg.permissions.api.entity.ImportExcelError;
import com.sptg.permissions.biz.service.ImportExcelErrorService;
import lombok.RequiredArgsConstructor;
import org.springframework.scheduling.annotation.Async;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * @author WFT
 * @date 2020/5/29
 * description:
 */
@RestController
@RequiredArgsConstructor
public class ImportExcelErrorController {

    private final ImportExcelErrorService errorService;

    @Async
    @PostMapping(value = "/import/excel/error/add")
    public void add(@RequestBody ImportExcelError excelError){
        excelError.setCreateTime(new Date());
        this.errorService.insert(excelError);
    }

    @GetMapping(value = "/import/excel/error/list/{flag}")
    public List<ImportExcelError> getListByFlag(@PathVariable(value = "flag") String flag){
        Wrapper<ImportExcelError> wrapper = new EntityWrapper<>();
        wrapper.eq("flag",flag);
        return this.errorService.selectList(wrapper);
    }

    @PostMapping(value = "/import/excel/error/deleteByIds")
    public void delete(@RequestBody List<Long> idList){
        this.errorService.deleteBatchIds(idList);
    }

}
