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.common.utils.poi.ExcelUtil; import com.ruoyi.dpc.domain.DpcEmployee; 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.vo.DpcEmployeeVO; import com.ruoyi.dpc.service.IDpcEmployeeService; 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 page = new Page<>(pageDomain.getPageNum(), pageDomain.getPageSize()); Page 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 list = employeeService.selectEmployeeListForExport(queryDTO); ExcelUtil util = new ExcelUtil<>(DpcEmployee.class); util.exportExcel(response, list, "员工信息数据"); } /** * 获取员工详细信息 */ @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)); } /** * 下载导入模板 */ @Operation(summary = "下载导入模板") @PostMapping("/importTemplate") public void importTemplate(HttpServletResponse response) { ExcelUtil util = new ExcelUtil<>(DpcEmployee.class); util.importTemplateExcel(response, "员工信息数据"); } /** * 导入员工信息 */ @Operation(summary = "导入员工信息") @PreAuthorize("@ss.hasPermi('dpc:employee:import')") @Log(title = "员工信息", businessType = BusinessType.IMPORT) @PostMapping("/importData") public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception { ExcelUtil util = new ExcelUtil<>(DpcEmployee.class); List list = util.importExcel(file.getInputStream()); List addDTOList = convertToAddDTOList(list); String message = employeeService.importEmployee(addDTOList, updateSupport); return success(message); } /** * 转换为AddDTO列表 */ private List convertToAddDTOList(List list) { return list.stream().map(entity -> { DpcEmployeeAddDTO dto = new DpcEmployeeAddDTO(); dto.setName(entity.getName()); dto.setTellerNo(entity.getTellerNo()); dto.setDeptId(entity.getDeptId()); dto.setIdCard(entity.getIdCard()); dto.setPhone(entity.getPhone()); dto.setHireDate(entity.getHireDate()); dto.setStatus(entity.getStatus()); return dto; }).toList(); } }