135 lines
4.9 KiB
Java
135 lines
4.9 KiB
Java
package com.ruoyi.dpc.controller;
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.ruoyi.common.annotation.Log;
|
|
import com.ruoyi.common.core.controller.BaseController;
|
|
import com.ruoyi.common.core.domain.AjaxResult;
|
|
import com.ruoyi.common.core.page.PageDomain;
|
|
import com.ruoyi.common.core.page.TableDataInfo;
|
|
import com.ruoyi.common.core.page.TableSupport;
|
|
import com.ruoyi.common.enums.BusinessType;
|
|
import com.ruoyi.dpc.domain.dto.DpcEmployeeAddDTO;
|
|
import com.ruoyi.dpc.domain.dto.DpcEmployeeEditDTO;
|
|
import com.ruoyi.dpc.domain.dto.DpcEmployeeQueryDTO;
|
|
import com.ruoyi.dpc.domain.excel.DpcEmployeeExcel;
|
|
import com.ruoyi.dpc.domain.vo.DpcEmployeeVO;
|
|
import com.ruoyi.dpc.service.IDpcEmployeeService;
|
|
import com.ruoyi.dpc.utils.EasyExcelUtil;
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
import jakarta.annotation.Resource;
|
|
import jakarta.servlet.http.HttpServletResponse;
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
import org.springframework.validation.annotation.Validated;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
import java.util.List;
|
|
|
|
/**
|
|
* 员工信息Controller
|
|
*
|
|
* @author ruoyi
|
|
* @date 2026-01-28
|
|
*/
|
|
@Tag(name = "员工信息管理")
|
|
@RestController
|
|
@RequestMapping("/dpc/employee")
|
|
public class DpcEmployeeController extends BaseController {
|
|
|
|
@Resource
|
|
private IDpcEmployeeService employeeService;
|
|
|
|
/**
|
|
* 查询员工列表
|
|
*/
|
|
@Operation(summary = "查询员工列表")
|
|
@PreAuthorize("@ss.hasPermi('dpc:employee:list')")
|
|
@GetMapping("/list")
|
|
public TableDataInfo list(DpcEmployeeQueryDTO queryDTO) {
|
|
// 使用MyBatis Plus分页
|
|
PageDomain pageDomain = TableSupport.buildPageRequest();
|
|
Page<DpcEmployeeVO> page = new Page<>(pageDomain.getPageNum(), pageDomain.getPageSize());
|
|
Page<DpcEmployeeVO> result = employeeService.selectEmployeePage(page, queryDTO);
|
|
return getDataTable(result.getRecords(), result.getTotal());
|
|
}
|
|
|
|
/**
|
|
* 导出员工列表
|
|
*/
|
|
@Operation(summary = "导出员工列表")
|
|
@PreAuthorize("@ss.hasPermi('dpc:employee:export')")
|
|
@Log(title = "员工信息", businessType = BusinessType.EXPORT)
|
|
@PostMapping("/export")
|
|
public void export(HttpServletResponse response, DpcEmployeeQueryDTO queryDTO) {
|
|
List<DpcEmployeeExcel> list = employeeService.selectEmployeeListForExport(queryDTO);
|
|
EasyExcelUtil.exportExcel(response, list, DpcEmployeeExcel.class, "员工信息");
|
|
}
|
|
|
|
/**
|
|
* 获取员工详细信息
|
|
*/
|
|
@Operation(summary = "获取员工详细信息")
|
|
@PreAuthorize("@ss.hasPermi('dpc:employee:query')")
|
|
@GetMapping(value = "/{employeeId}")
|
|
public AjaxResult getInfo(@PathVariable Long employeeId) {
|
|
return success(employeeService.selectEmployeeById(employeeId));
|
|
}
|
|
|
|
/**
|
|
* 新增员工
|
|
*/
|
|
@Operation(summary = "新增员工")
|
|
@PreAuthorize("@ss.hasPermi('dpc:employee:add')")
|
|
@Log(title = "员工信息", businessType = BusinessType.INSERT)
|
|
@PostMapping
|
|
public AjaxResult add(@Validated @RequestBody DpcEmployeeAddDTO addDTO) {
|
|
return toAjax(employeeService.insertEmployee(addDTO));
|
|
}
|
|
|
|
/**
|
|
* 修改员工
|
|
*/
|
|
@Operation(summary = "修改员工")
|
|
@PreAuthorize("@ss.hasPermi('dpc:employee:edit')")
|
|
@Log(title = "员工信息", businessType = BusinessType.UPDATE)
|
|
@PutMapping
|
|
public AjaxResult edit(@Validated @RequestBody DpcEmployeeEditDTO editDTO) {
|
|
return toAjax(employeeService.updateEmployee(editDTO));
|
|
}
|
|
|
|
/**
|
|
* 删除员工
|
|
*/
|
|
@Operation(summary = "删除员工")
|
|
@PreAuthorize("@ss.hasPermi('dpc:employee:remove')")
|
|
@Log(title = "员工信息", businessType = BusinessType.DELETE)
|
|
@DeleteMapping("/{employeeIds}")
|
|
public AjaxResult remove(@PathVariable Long[] employeeIds) {
|
|
return toAjax(employeeService.deleteEmployeeByIds(employeeIds));
|
|
}
|
|
|
|
/**
|
|
* 下载带字典下拉框的导入模板
|
|
* 使用@DictDropdown注解自动添加下拉框
|
|
*/
|
|
@Operation(summary = "下载导入模板")
|
|
@PostMapping("/importTemplate")
|
|
public void importTemplate(HttpServletResponse response) {
|
|
EasyExcelUtil.importTemplateWithDictDropdown(response, DpcEmployeeExcel.class, "员工信息");
|
|
}
|
|
|
|
/**
|
|
* 导入员工信息
|
|
*/
|
|
@Operation(summary = "导入员工信息")
|
|
@PreAuthorize("@ss.hasPermi('dpc:employee:import')")
|
|
@Log(title = "员工信息", businessType = BusinessType.IMPORT)
|
|
@PostMapping("/importData")
|
|
public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception {
|
|
List<DpcEmployeeExcel> list = EasyExcelUtil.importExcel(file.getInputStream(), DpcEmployeeExcel.class);
|
|
String message = employeeService.importEmployee(list, updateSupport);
|
|
return success(message);
|
|
}
|
|
}
|