package cn.lihongjie.coal.employee.controller;

import cn.lihongjie.coal.annotation.OrgScope;
import cn.lihongjie.coal.annotation.SysLog;
import cn.lihongjie.coal.base.dto.CommonQuery;
import cn.lihongjie.coal.base.dto.IdRequest;
import cn.lihongjie.coal.common.Base64File;
import cn.lihongjie.coal.employee.dto.CreateEmployeeDto;
import cn.lihongjie.coal.employee.dto.EmployeeDto;
import cn.lihongjie.coal.employee.dto.ImportEmpFromExcelRequest;
import cn.lihongjie.coal.employee.dto.UpdateEmployeeDto;
import cn.lihongjie.coal.employee.service.EmployeeService;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/employee")
@SysLog(module = "员工信息")
@Slf4j
@OrgScope
public class EmployeeController {
    @Autowired private EmployeeService service;

    @PostMapping("/create")
    public EmployeeDto create(@RequestBody CreateEmployeeDto request) {
        return this.service.create(request);
    }

    @PostMapping("/update")
    public EmployeeDto update(@RequestBody UpdateEmployeeDto request) {
        return this.service.update(request);
    }

    @PostMapping("/delete")
    public Object delete(@RequestBody IdRequest request) {
        this.service.delete(request);
        return true;
    }

    @PostMapping("/getById")
    public EmployeeDto getById(@RequestBody IdRequest request) {
        return this.service.getById(request.getId());
    }

    @PostMapping("/list")
    public Page<EmployeeDto> list(@RequestBody CommonQuery request) {
        return this.service.list(request);
    }


    @PostMapping("/importTemplate")
    public Base64File importTemplate() {
        return (this.service.generateImportTemplate());
    }


    @PostMapping("/import")
    public Object importData(@RequestBody ImportEmpFromExcelRequest request) {
        this.service.importFromExcel(request);

        return true;
    }
}
