|
@@ -0,0 +1,123 @@
|
|
|
+package com.chelvc.cloud.admin.controller;
|
|
|
+
|
|
|
+import javax.validation.Valid;
|
|
|
+import javax.validation.constraints.Min;
|
|
|
+
|
|
|
+import com.chelvc.cloud.admin.copier.EmployeeCopier;
|
|
|
+import com.chelvc.cloud.admin.vo.MineVO;
|
|
|
+import com.chelvc.cloud.uc.api.dto.EmployeeDTO;
|
|
|
+import com.chelvc.cloud.uc.api.dto.EmployeeDetailDTO;
|
|
|
+import com.chelvc.cloud.uc.api.param.EmployeeModifyParam;
|
|
|
+import com.chelvc.cloud.uc.api.param.EmployeePagingParam;
|
|
|
+import com.chelvc.cloud.uc.api.param.PasswordResetParam;
|
|
|
+import com.chelvc.cloud.uc.api.param.PasswordUpdateParam;
|
|
|
+import com.chelvc.cloud.uc.api.service.EmployeeService;
|
|
|
+import com.chelvc.platform.base.annotation.UnifiedResponseBody;
|
|
|
+import com.chelvc.platform.base.context.SessionContextHolder;
|
|
|
+import com.chelvc.platform.base.model.Pagination;
|
|
|
+import com.chelvc.platform.base.util.ErrorUtils;
|
|
|
+import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
+import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
+import org.springframework.web.bind.annotation.PathVariable;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.PutMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 员工接口
|
|
|
+ *
|
|
|
+ * @author Woody
|
|
|
+ * @date 2021/10/20
|
|
|
+ */
|
|
|
+@Validated
|
|
|
+@RestController
|
|
|
+@UnifiedResponseBody
|
|
|
+@PreAuthorize("isType('ADMIN')")
|
|
|
+public class EmployeeController {
|
|
|
+ @DubboReference
|
|
|
+ private EmployeeService employeeService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增员工
|
|
|
+ *
|
|
|
+ * @param param 新增参数
|
|
|
+ * @return 员工主键
|
|
|
+ */
|
|
|
+ @PostMapping("/employee")
|
|
|
+ public Long addEmployee(@RequestBody @Valid EmployeeModifyParam param) {
|
|
|
+ return this.employeeService.addEmployee(param);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改员工
|
|
|
+ *
|
|
|
+ * @param id 员工主键
|
|
|
+ * @param param 修改参数
|
|
|
+ */
|
|
|
+ @PutMapping("/employee/{id}")
|
|
|
+ public void updateEmployee(@PathVariable("id") @Min(value = 1, message = "员工主键不能小于1") Long id,
|
|
|
+ @RequestBody @Valid EmployeeModifyParam param) {
|
|
|
+ this.employeeService.updateEmployee(id, param);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 需改当前员工密码
|
|
|
+ *
|
|
|
+ * @param param 修改参数
|
|
|
+ */
|
|
|
+ @PutMapping("/employee/mine/password")
|
|
|
+ public void updateMinePassword(@RequestBody @Valid PasswordUpdateParam param) {
|
|
|
+ Long id = SessionContextHolder.getSession().getId();
|
|
|
+ this.employeeService.updateEmployeePassword(id, param);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 重置员工密码
|
|
|
+ *
|
|
|
+ * @param id 员工主键
|
|
|
+ * @param param 修改参数
|
|
|
+ */
|
|
|
+ @PutMapping("/employee/{id}/password")
|
|
|
+ public void updateEmployeePassword(@PathVariable("id") @Min(value = 1, message = "员工主键不能小于1") Long id,
|
|
|
+ @RequestBody @Valid PasswordResetParam param) {
|
|
|
+ this.employeeService.resetEmployeePassword(id, param);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取当前员工信息
|
|
|
+ *
|
|
|
+ * @return 员工信息
|
|
|
+ */
|
|
|
+ @GetMapping("/employee/mine")
|
|
|
+ public MineVO getMine() {
|
|
|
+ EmployeeDetailDTO employee = this.employeeService.getMine();
|
|
|
+ return EmployeeCopier.INSTANCE.employee2mine(employee);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取员工信息
|
|
|
+ *
|
|
|
+ * @param id 员工主键
|
|
|
+ * @return 员工信息
|
|
|
+ */
|
|
|
+ @GetMapping("/employee/{id}")
|
|
|
+ public EmployeeDTO getEmployee(@PathVariable("id") @Min(value = 1, message = "员工主键不能小于1") Long id) {
|
|
|
+ EmployeeDTO employee = this.employeeService.getEmployee(id);
|
|
|
+ ErrorUtils.requireResource(employee, "员工不存在");
|
|
|
+ return employee;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询员工分页
|
|
|
+ *
|
|
|
+ * @param param 查询参数
|
|
|
+ * @return 员工分页信息
|
|
|
+ */
|
|
|
+ @GetMapping("/employee/paging")
|
|
|
+ public Pagination<EmployeeDTO> getEmployeePaging(@Valid EmployeePagingParam param) {
|
|
|
+ return this.employeeService.getEmployeePaging(param);
|
|
|
+ }
|
|
|
+}
|