mirror of
https://gitee.com/lab1024/smart-admin.git
synced 2025-11-05 18:23:47 +08:00
1、优化与完善个人中心的资料更新;2、修改员工DAO层的方法参数
This commit is contained in:
@@ -57,11 +57,11 @@ public class EmployeeController {
|
||||
return employeeService.updateEmployee(employeeUpdateForm);
|
||||
}
|
||||
|
||||
@Operation(summary = "更新登录人信息 @author 善逸")
|
||||
@PostMapping("/employee/update/login")
|
||||
public ResponseDTO<String> updateByLogin(@Valid @RequestBody EmployeeUpdateForm employeeUpdateForm) {
|
||||
employeeUpdateForm.setEmployeeId(SmartRequestUtil.getRequestUserId());
|
||||
return employeeService.updateEmployee(employeeUpdateForm);
|
||||
@Operation(summary = "更新员工个人中心信息 @author 善逸")
|
||||
@PostMapping("/employee/update/center")
|
||||
public ResponseDTO<String> updateCenter(@Valid @RequestBody EmployeeUpdateCenterForm updateCenterForm) {
|
||||
updateCenterForm.setEmployeeId(SmartRequestUtil.getRequestUserId());
|
||||
return employeeService.updateCenter(updateCenterForm);
|
||||
}
|
||||
|
||||
@Operation(summary = "更新登录人头像 @author 善逸")
|
||||
|
||||
@@ -34,19 +34,16 @@ public interface EmployeeDao extends BaseMapper<EmployeeEntity> {
|
||||
*/
|
||||
List<EmployeeVO> selectEmployeeByDisabledAndDeleted(@Param("disabledFlag") Boolean disabledFlag, @Param("deletedFlag") Boolean deletedFlag);
|
||||
|
||||
|
||||
/**
|
||||
* 更新禁用状态
|
||||
*/
|
||||
void updateDisableFlag(@Param("employeeId") Long employeeId, @Param("disabledFlag") Boolean disabledFlag);
|
||||
|
||||
|
||||
/**
|
||||
* 通过登录名查询
|
||||
*/
|
||||
EmployeeEntity getByLoginName(@Param("loginName") String loginName, @Param("deletedFlag") Boolean deletedFlag);
|
||||
|
||||
|
||||
/**
|
||||
* 通过姓名查询
|
||||
*/
|
||||
@@ -57,6 +54,11 @@ public interface EmployeeDao extends BaseMapper<EmployeeEntity> {
|
||||
*/
|
||||
EmployeeEntity getByPhone(@Param("phone") String phone, @Param("deletedFlag") Boolean deletedFlag);
|
||||
|
||||
/**
|
||||
* 通过邮箱账号查询
|
||||
*/
|
||||
EmployeeEntity getByEmail(@Param("email") String email, @Param("deletedFlag") Boolean deletedFlag);
|
||||
|
||||
/**
|
||||
* 获取所有员工
|
||||
*/
|
||||
@@ -64,7 +66,6 @@ public interface EmployeeDao extends BaseMapper<EmployeeEntity> {
|
||||
|
||||
/**
|
||||
* 获取某个部门员工数
|
||||
*
|
||||
*/
|
||||
Integer countByDepartmentId(@Param("departmentId") Long departmentId, @Param("deletedFlag") Boolean deletedFlag);
|
||||
|
||||
@@ -73,25 +74,21 @@ public interface EmployeeDao extends BaseMapper<EmployeeEntity> {
|
||||
*/
|
||||
List<EmployeeVO> getEmployeeByIds(@Param("employeeIds") Collection<Long> employeeIds);
|
||||
|
||||
|
||||
/**
|
||||
* 查询单个员工信息
|
||||
*/
|
||||
EmployeeVO getEmployeeById(@Param("employeeId") Long employeeId);
|
||||
|
||||
|
||||
/**
|
||||
* 获取某个部门的员工
|
||||
*/
|
||||
List<EmployeeEntity> selectByDepartmentId(@Param("departmentId") Long departmentId, @Param("deletedFlag") Boolean deletedFlag);
|
||||
|
||||
|
||||
/**
|
||||
* 查询某些部门下用户名是xxx的员工
|
||||
*/
|
||||
List<EmployeeEntity> selectByActualName(@Param("departmentIdList") List<Long> departmentIdList, @Param("actualName") String actualName, @Param("deletedFlag") Boolean deletedFlag);
|
||||
|
||||
|
||||
/**
|
||||
* 获取某批部门的员工Id
|
||||
*/
|
||||
|
||||
@@ -51,17 +51,19 @@ public class EmployeeAddForm {
|
||||
@Pattern(regexp = SmartVerificationUtil.PHONE_REGEXP, message = "手机号格式不正确")
|
||||
private String phone;
|
||||
|
||||
@Schema(description = "邮箱")
|
||||
@Schema(description = "邮箱账号")
|
||||
@NotNull(message = "邮箱账号不能为空")
|
||||
@Pattern(regexp = SmartVerificationUtil.EMAIL, message = "邮箱账号格式不正确")
|
||||
private String email;
|
||||
|
||||
@Schema(description = "职务级别ID")
|
||||
private Long positionId;
|
||||
|
||||
@Schema(description = "角色列表")
|
||||
private List<Long> roleIdList;
|
||||
|
||||
@Schema(description = "备注")
|
||||
@Length(max = 30, message = "备注最多200字符")
|
||||
@Length(max = 200, message = "备注最多200字符")
|
||||
private String remark;
|
||||
|
||||
@Schema(description = "职务级别ID")
|
||||
private Long positionId;
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
package net.lab1024.sa.admin.module.system.employee.domain.form;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Pattern;
|
||||
import lombok.Data;
|
||||
import net.lab1024.sa.base.common.enumeration.GenderEnum;
|
||||
import net.lab1024.sa.base.common.swagger.SchemaEnum;
|
||||
import net.lab1024.sa.base.common.util.SmartVerificationUtil;
|
||||
import net.lab1024.sa.base.common.validator.enumeration.CheckEnum;
|
||||
import org.hibernate.validator.constraints.Length;
|
||||
|
||||
/**
|
||||
* 更新员工个人中心信息
|
||||
*
|
||||
* @Author 1024创新实验室: 开云
|
||||
* @Date 2021-12-20 21:06:49
|
||||
* @Wechat zhuoda1024
|
||||
* @Email lab1024@163.com
|
||||
* @Copyright <a href="https://1024lab.net">1024创新实验室</a>
|
||||
*/
|
||||
@Data
|
||||
public class EmployeeUpdateCenterForm {
|
||||
|
||||
@Schema(hidden = true)
|
||||
private Long employeeId;
|
||||
|
||||
@Schema(description = "姓名")
|
||||
@NotNull(message = "姓名不能为空")
|
||||
@Length(max = 30, message = "姓名最多30字符")
|
||||
private String actualName;
|
||||
|
||||
@SchemaEnum(GenderEnum.class)
|
||||
@CheckEnum(value = GenderEnum.class, message = "性别错误")
|
||||
private Integer gender;
|
||||
|
||||
@Schema(description = "手机号")
|
||||
@NotNull(message = "手机号不能为空")
|
||||
@Pattern(regexp = SmartVerificationUtil.PHONE_REGEXP, message = "手机号格式不正确")
|
||||
private String phone;
|
||||
|
||||
@Schema(description = "邮箱账号")
|
||||
@NotNull(message = "邮箱账号不能为空")
|
||||
@Pattern(regexp = SmartVerificationUtil.EMAIL, message = "邮箱账号格式不正确")
|
||||
private String email;
|
||||
|
||||
@Schema(description = "职务级别ID")
|
||||
private Long positionId;
|
||||
|
||||
@Schema(description = "头像")
|
||||
private String avatar;
|
||||
|
||||
@Schema(description = "备注")
|
||||
@Length(max = 200, message = "备注最多200字符")
|
||||
private String remark;
|
||||
}
|
||||
@@ -168,19 +168,14 @@ public class EmployeeService {
|
||||
return ResponseDTO.userErrorParam("部门不存在");
|
||||
}
|
||||
|
||||
|
||||
EmployeeEntity existEntity = employeeDao.getByLoginName(employeeUpdateForm.getLoginName(), null);
|
||||
if (null != existEntity && !Objects.equals(existEntity.getEmployeeId(), employeeId)) {
|
||||
return ResponseDTO.userErrorParam("登录名重复");
|
||||
// 检查唯一性
|
||||
ResponseDTO<String> checkResponse = checkUniqueness(employeeId, employeeUpdateForm.getLoginName(), employeeUpdateForm.getPhone(), employeeUpdateForm.getEmail());
|
||||
if (!checkResponse.getOk()) {
|
||||
return checkResponse;
|
||||
}
|
||||
|
||||
existEntity = employeeDao.getByPhone(employeeUpdateForm.getPhone(), null);
|
||||
if (null != existEntity && !Objects.equals(existEntity.getEmployeeId(), employeeId)) {
|
||||
return ResponseDTO.userErrorParam("手机号已存在");
|
||||
}
|
||||
|
||||
// 不更新密码
|
||||
EmployeeEntity entity = SmartBeanUtil.copy(employeeUpdateForm, EmployeeEntity.class);
|
||||
// 不更新密码
|
||||
entity.setLoginPwd(null);
|
||||
|
||||
// 更新数据
|
||||
@@ -192,6 +187,58 @@ public class EmployeeService {
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新员工个人中心信息
|
||||
*/
|
||||
public ResponseDTO<String> updateCenter(EmployeeUpdateCenterForm updateCenterForm) {
|
||||
|
||||
Long employeeId = updateCenterForm.getEmployeeId();
|
||||
EmployeeEntity employeeEntity = employeeDao.selectById(employeeId);
|
||||
if (null == employeeEntity) {
|
||||
return ResponseDTO.error(UserErrorCode.DATA_NOT_EXIST);
|
||||
}
|
||||
|
||||
// 检查唯一性 登录账号不能修改则不需要检查
|
||||
ResponseDTO<String> checkResponse = checkUniqueness(employeeId, "", updateCenterForm.getPhone(), updateCenterForm.getEmail());
|
||||
if (!checkResponse.getOk()) {
|
||||
return checkResponse;
|
||||
}
|
||||
|
||||
EmployeeEntity employee = SmartBeanUtil.copy(updateCenterForm, EmployeeEntity.class);
|
||||
// 不更新密码
|
||||
employee.setLoginPwd(null);
|
||||
|
||||
// 更新数据
|
||||
employeeDao.updateById(employee);
|
||||
|
||||
// 清除员工缓存
|
||||
loginService.clearLoginEmployeeCache(employeeId);
|
||||
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查唯一性
|
||||
*/
|
||||
private ResponseDTO<String> checkUniqueness(Long employeeId, String loginName, String phone, String email) {
|
||||
EmployeeEntity existEntity = employeeDao.getByLoginName(loginName, null);
|
||||
if (null != existEntity && !Objects.equals(existEntity.getEmployeeId(), employeeId)) {
|
||||
return ResponseDTO.userErrorParam("登录名重复");
|
||||
}
|
||||
|
||||
existEntity = employeeDao.getByPhone(phone, null);
|
||||
if (null != existEntity && !Objects.equals(existEntity.getEmployeeId(), employeeId)) {
|
||||
return ResponseDTO.userErrorParam("手机号已存在");
|
||||
}
|
||||
|
||||
existEntity = employeeDao.getByEmail(email, null);
|
||||
if (null != existEntity && !Objects.equals(existEntity.getEmployeeId(), employeeId)) {
|
||||
return ResponseDTO.userErrorParam("邮箱账号已存在");
|
||||
}
|
||||
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 更新登录人头像
|
||||
|
||||
@@ -46,6 +46,12 @@ public class RequestEmployee implements RequestUser {
|
||||
@Schema(description = "部门名称")
|
||||
private String departmentName;
|
||||
|
||||
@Schema(description = "职务级别ID")
|
||||
private Long positionId;
|
||||
|
||||
@Schema(description = "邮箱")
|
||||
private String email;
|
||||
|
||||
@Schema(description = "是否禁用")
|
||||
private Boolean disabledFlag;
|
||||
|
||||
|
||||
@@ -33,14 +33,12 @@
|
||||
</where>
|
||||
</select>
|
||||
|
||||
|
||||
<update id="updateDisableFlag">
|
||||
UPDATE t_employee
|
||||
SET disabled_flag = #{disabledFlag}
|
||||
WHERE employee_id = #{employeeId}
|
||||
</update>
|
||||
|
||||
|
||||
<select id="getByLoginName" resultType="net.lab1024.sa.admin.module.system.employee.domain.entity.EmployeeEntity">
|
||||
SELECT *
|
||||
FROM t_employee
|
||||
@@ -63,7 +61,6 @@
|
||||
</where>
|
||||
</select>
|
||||
|
||||
|
||||
<select id="getByPhone" resultType="net.lab1024.sa.admin.module.system.employee.domain.entity.EmployeeEntity">
|
||||
SELECT *
|
||||
FROM t_employee
|
||||
@@ -75,6 +72,16 @@
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="getByEmail" resultType="net.lab1024.sa.admin.module.system.employee.domain.entity.EmployeeEntity">
|
||||
SELECT *
|
||||
FROM t_employee
|
||||
<where>
|
||||
email = #{email}
|
||||
<if test="deletedFlag != null">
|
||||
AND deleted_flag = #{deletedFlag}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="listAll" resultType="net.lab1024.sa.admin.module.system.employee.domain.vo.EmployeeVO">
|
||||
SELECT *
|
||||
@@ -88,9 +95,7 @@
|
||||
department_id = #{departmentId} AND deleted_flag = #{deletedFlag}
|
||||
</select>
|
||||
|
||||
|
||||
<select id="selectByDepartmentId"
|
||||
resultType="net.lab1024.sa.admin.module.system.employee.domain.entity.EmployeeEntity">
|
||||
<select id="selectByDepartmentId" resultType="net.lab1024.sa.admin.module.system.employee.domain.entity.EmployeeEntity">
|
||||
SELECT *
|
||||
FROM t_employee
|
||||
<where>
|
||||
@@ -102,8 +107,7 @@
|
||||
ORDER BY create_time DESC
|
||||
</select>
|
||||
|
||||
<select id="selectByActualName"
|
||||
resultType="net.lab1024.sa.admin.module.system.employee.domain.entity.EmployeeEntity">
|
||||
<select id="selectByActualName" resultType="net.lab1024.sa.admin.module.system.employee.domain.entity.EmployeeEntity">
|
||||
SELECT * FROM t_employee
|
||||
<where>
|
||||
actual_name = #{actualName}
|
||||
@@ -132,7 +136,6 @@
|
||||
ORDER BY create_time DESC
|
||||
</select>
|
||||
|
||||
|
||||
<select id="getEmployeeId" resultType="java.lang.Long">
|
||||
SELECT employee_id
|
||||
FROM t_employee
|
||||
@@ -164,7 +167,6 @@
|
||||
ORDER BY create_time DESC
|
||||
</select>
|
||||
|
||||
|
||||
<select id="getEmployeeById" resultType="net.lab1024.sa.admin.module.system.employee.domain.vo.EmployeeVO">
|
||||
SELECT t_employee.*,
|
||||
t_department.name AS departmentName
|
||||
@@ -173,8 +175,7 @@
|
||||
where t_employee.employee_id = #{employeeId}
|
||||
</select>
|
||||
|
||||
<select id="selectEmployeeByDisabledAndDeleted"
|
||||
resultType="net.lab1024.sa.admin.module.system.employee.domain.vo.EmployeeVO">
|
||||
<select id="selectEmployeeByDisabledAndDeleted" resultType="net.lab1024.sa.admin.module.system.employee.domain.vo.EmployeeVO">
|
||||
SELECT
|
||||
t_employee.*,
|
||||
t_department.name AS departmentName
|
||||
@@ -196,5 +197,4 @@
|
||||
WHERE employee_id = #{employeeId}
|
||||
</update>
|
||||
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user