更新0822

This commit is contained in:
xyc 2025-08-22 11:09:11 +08:00
parent 06560969c0
commit 6e3997af97
7 changed files with 166 additions and 0 deletions

View File

@ -132,6 +132,10 @@
su.status,
su.avatar AS avatar,
dsc.folder_id AS folderId,
dsc.safe_date AS safeDate,
dsc.formal_date AS formalDate,
dsc.address AS address,
dsc.id_number AS idNumber,
GROUP_CONCAT(DISTINCT sr2.name SEPARATOR ',') AS roleNames
FROM
system_users su

View File

@ -90,6 +90,31 @@ public class RepairStaffController {
return CommonResult.ok();
}
/**
* 新增员工
*
* @param repairStaff 员工信息
* @return
*/
@PostMapping("/insert")
public CommonResult<?> insert(@RequestBody RepairStaffSaveVo repairStaff) {
repairStaffService.insert(repairStaff);
return CommonResult.ok();
}
/**
* @Author
* @Description 更新员工
* @Date 10:38 2025/8/21
* @Param [repairStaff]
* @return cn.iocoder.yudao.framework.common.pojo.CommonResult<?>
**/
@PostMapping("/updateStaff")
public CommonResult<?> updateStaff(@RequestBody RepairStaffSaveVo repairStaff) {
repairStaffService.updateStaff(repairStaff);
return CommonResult.ok();
}
@GetMapping("/listSelectUser")
public CommonResult<?> listSelectUser(@Valid UserPageReqVO pageReqVO) {
// 查询目前所有的userId

View File

@ -5,6 +5,7 @@ import cn.iocoder.yudao.module.system.api.user.dto.UserDTO;
import cn.iocoder.yudao.module.system.dal.dataobject.permission.RoleDO;
import lombok.Data;
import java.util.Date;
import java.util.List;
@Data
@ -60,4 +61,13 @@ public class RepairStaff {
* 文件夹id
*/
private String folderId;
/** 家庭住址 */
private String address;
private String IdNumber;
private Date safeDate;
private Date formalDate;
}

View File

@ -14,6 +14,7 @@ public class RepairStaffSaveVo {
* 选择的员工
*/
public List<UserDTO> repairStaffs;
public UserDTO repairStaff;
/**
* 角色id
*/

View File

@ -40,4 +40,22 @@ public interface RepairStaffService {
* @date: 2025/8/11 13:22
*/
UserDTO getStaff(Long id);
/**
* @Author
* @Description 新增员工
* @Date 16:17 2025/8/20
* @Param [repairStaff]
* @return void
**/
void insert(RepairStaffSaveVo repairStaff);
/**
* @Author
* @Description
* @Date 10:44 2025/8/21
* @Param [repairStaff]
* @return void
**/
void updateStaff(RepairStaffSaveVo repairStaff);
}

View File

@ -1,6 +1,7 @@
package cn.iocoder.yudao.module.base.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.iocoder.yudao.common.CommonErrorCodeConstants;
@ -154,6 +155,100 @@ public class RepairStaffServiceImpl implements RepairStaffService {
return companyStaffService.getStaff(id);
}
/**
* @return void
* @Author
* @Description 新增员工
* @Date 16:17 2025/8/20
* @Param [repairStaff]
*/
@Override
public void insert(RepairStaffSaveVo repairStaff) {
// 获取当前登录用户的详细信息
AdminUserRespDTO loginUser = getLoginUser();
// 判断用户是否存在
AdminUserRespDTO checkUserName = adminUserApi.getUserByUsername(repairStaff.getRepairStaffs().get(0).getUsername());
if (ObjectUtil.isEmpty(checkUserName)) {
// 新增
Long user = adminUserApi.createUser(repairStaff.getRepairStaffs().get(0));
repairStaff.getRepairStaffs().get(0).setId(user);
}
// 1. 分配角色
repairStaff.getRepairStaffs().forEach(item -> {
permissionService.assignUserRoleByServicePackageId(item.getId(), repairStaff.getRoleIds(), SystemEnum.REPAIR.getCode());
});
// 2. 查看员工表中是否存在
List<Long> oldIds = repairStaff.getRepairStaffs().stream().map(UserDTO::getId).collect(Collectors.toList());
List<CompanyStaff> staffList = companyStaffService.list(Wrappers.<CompanyStaff>lambdaQuery()
.in(CompanyStaff::getUserId, oldIds));
// 获取员工表中已有的用户ID集合
Set<Long> existUserIds = staffList.stream()
.map(CompanyStaff::getUserId)
.collect(Collectors.toSet());
// 找出不存在于员工表中的用户ID
List<UserDTO> notExistUsers = repairStaff.getRepairStaffs().stream()
.filter(user -> !existUserIds.contains(user.getId()))
.collect(Collectors.toList());
/* 插入员工库 */
DeptRespDTO loginDept = getLoginDept(loginUser.getDeptId());
// 添加员工
if (CollectionUtil.isNotEmpty(notExistUsers)) {
List<CompanyStaff> companyStaffs = new ArrayList<>();
for (UserDTO notExistUser : notExistUsers) {
CompanyStaff companyStaff = new CompanyStaff();
BeanUtil.copyProperties(notExistUser, companyStaff);
companyStaff.setId(null);
companyStaff.setCreateTime(null);
companyStaff.setUpdateTime(null);
companyStaff.setCreator(null);
companyStaff.setUpdater(null);
// 1 获取当前登录用户的企业信息给添加的员工
// 2 生成唯一推广码
String uniqueCode = uniqueCodeService.createUniqueCode();
if (!ObjectUtil.isNotEmpty(uniqueCode)) {
throw exception(CommonErrorCodeConstants.UNIQUE_CODE_CREATE_REPEAT);
}
companyStaff.setCorpId(loginDept.getCorpId());
companyStaff.setUserId(notExistUser.getId());
companyStaff.setName(notExistUser.getNickname());
companyStaff.setTel(notExistUser.getUsername());
companyStaff.setUniqueCode(uniqueCode);
companyStaffs.add(companyStaff);
}
companyStaffService.saveBatch(companyStaffs);
}
}
/**
* @return void
* @Author
* @Description
* @Date 10:44 2025/8/21
* @Param [repairStaff]
*/
@Override
public void updateStaff(RepairStaffSaveVo repairStaff) {
UserDTO staff = repairStaff.getRepairStaff();
CompanyStaff companyStaff = BeanUtil.copyProperties(staff, CompanyStaff.class);
companyStaff.setCreator(null);
companyStaff.setUpdater(null);
companyStaff.setUpdateTime(null);
companyStaff.setCreateTime(null);
companyStaff.setDeptId(null);
companyStaff.setId(null);
companyStaffService.update(companyStaff, Wrappers.<CompanyStaff>lambdaUpdate()
.eq(CompanyStaff::getUserId, staff.getId()));
}
/**
* 获取当前登录用户的部门详细信息
*

View File

@ -2,6 +2,8 @@ package cn.iocoder.yudao.module.system.api.user.dto;
import lombok.Data;
import java.util.Date;
@Data
public class UserDTO {
/**
@ -68,4 +70,15 @@ public class UserDTO {
*/
private String folderId;
// ================== 员工字段 ==================
/** 家庭住址 */
private String address;
private String IdNumber;
private Date safeDate;
private Date formalDate;
}