|
@@ -0,0 +1,194 @@
|
|
|
+package org.dromara.service.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import org.dromara.common.core.utils.MapstructUtils;
|
|
|
+import org.dromara.common.core.utils.StringUtils;
|
|
|
+import org.dromara.common.mybatis.core.page.PageQuery;
|
|
|
+import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
|
+import org.dromara.common.tenant.helper.TenantHelper;
|
|
|
+import org.dromara.domain.staffManage.StaffManage;
|
|
|
+import org.dromara.domain.staffManage.bo.StaffManageBo;
|
|
|
+import org.dromara.domain.staffManage.vo.StaffManageVo;
|
|
|
+import org.dromara.mapper.StaffManageMapper;
|
|
|
+import org.dromara.service.IStaffManageService;
|
|
|
+import org.dromara.system.domain.SysRole;
|
|
|
+import org.dromara.system.domain.SysUserTenant;
|
|
|
+import org.dromara.system.domain.bo.SysUserBo;
|
|
|
+import org.dromara.system.domain.vo.SysRoleVo;
|
|
|
+import org.dromara.system.mapper.SysRoleMapper;
|
|
|
+import org.dromara.system.mapper.SysUserTenantMapper;
|
|
|
+import org.dromara.system.service.ISysUserService;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import java.util.Collection;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+import static org.dromara.common.core.constant.Constants.TWO;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 员工管理Service业务层处理
|
|
|
+ *
|
|
|
+ * @author boman
|
|
|
+ * @date 2025-04-10
|
|
|
+ */
|
|
|
+@RequiredArgsConstructor
|
|
|
+@Service
|
|
|
+public class StaffManageServiceImpl implements IStaffManageService {
|
|
|
+
|
|
|
+ private final StaffManageMapper baseMapper;
|
|
|
+ private final SysUserTenantMapper sysUserTenantMapper;
|
|
|
+ private final SysRoleMapper sysRoleMapper;
|
|
|
+ private final ISysUserService sysUserService;
|
|
|
+ /**
|
|
|
+ * 查询员工管理
|
|
|
+ *
|
|
|
+ * @param staffId 主键
|
|
|
+ * @return 员工管理
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public StaffManageVo queryById(Long staffId){
|
|
|
+ return baseMapper.selectVoById(staffId);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页查询员工管理列表
|
|
|
+ *
|
|
|
+ * @param bo 查询条件
|
|
|
+ * @param pageQuery 分页参数
|
|
|
+ * @return 员工管理分页列表
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public TableDataInfo<StaffManageVo> queryPageList(StaffManageBo bo, PageQuery pageQuery) {
|
|
|
+ LambdaQueryWrapper<StaffManage> lqw = buildQueryWrapper(bo);
|
|
|
+ Page<StaffManageVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
|
|
+ return TableDataInfo.build(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询符合条件的员工管理列表
|
|
|
+ *
|
|
|
+ * @param bo 查询条件
|
|
|
+ * @return 员工管理列表
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<StaffManageVo> queryList(StaffManageBo bo) {
|
|
|
+ LambdaQueryWrapper<StaffManage> lqw = buildQueryWrapper(bo);
|
|
|
+ return baseMapper.selectVoList(lqw);
|
|
|
+ }
|
|
|
+
|
|
|
+ private LambdaQueryWrapper<StaffManage> buildQueryWrapper(StaffManageBo bo) {
|
|
|
+ Map<String, Object> params = bo.getParams();
|
|
|
+ LambdaQueryWrapper<StaffManage> lqw = Wrappers.lambdaQuery();
|
|
|
+ lqw.orderByAsc(StaffManage::getStaffId);
|
|
|
+ lqw.eq(bo.getUserId() != null, StaffManage::getUserId, bo.getUserId());
|
|
|
+ lqw.like(StringUtils.isNotBlank(bo.getStaffName()), StaffManage::getStaffName, bo.getStaffName());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getGender()), StaffManage::getGender, bo.getGender());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getStaffCategory()), StaffManage::getStaffCategory, bo.getStaffCategory());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getMaintenanceCategory()), StaffManage::getMaintenanceCategory, bo.getMaintenanceCategory());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getPhoneNumber()), StaffManage::getPhoneNumber, bo.getPhoneNumber());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getAvatarPhoto()), StaffManage::getAvatarPhoto, bo.getAvatarPhoto());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getIdCard()), StaffManage::getIdCard, bo.getIdCard());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getIdCardFront()), StaffManage::getIdCardFront, bo.getIdCardFront());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getIdCardBack()), StaffManage::getIdCardBack, bo.getIdCardBack());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getCertificate()), StaffManage::getCertificate, bo.getCertificate());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getStatus()), StaffManage::getStatus, bo.getStatus());
|
|
|
+ return lqw;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增员工管理
|
|
|
+ *
|
|
|
+ * @param bo 员工管理
|
|
|
+ * @return 是否新增成功
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean insertByBo(StaffManageBo bo) {
|
|
|
+ StaffManage add = MapstructUtils.convert(bo, StaffManage.class);
|
|
|
+ validEntityBeforeSave(add);
|
|
|
+ boolean flag = baseMapper.insert(add) > 0;
|
|
|
+ if (flag) {
|
|
|
+ bo.setStaffId(add.getStaffId());
|
|
|
+ }
|
|
|
+ return flag;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改员工管理
|
|
|
+ *
|
|
|
+ * @param bo 员工管理
|
|
|
+ * @return 是否修改成功
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean updateByBo(StaffManageBo bo) {
|
|
|
+ StaffManage update = MapstructUtils.convert(bo, StaffManage.class);
|
|
|
+ validEntityBeforeSave(update);
|
|
|
+ return baseMapper.updateById(update) > 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存前的数据校验
|
|
|
+ */
|
|
|
+ private void validEntityBeforeSave(StaffManage entity){
|
|
|
+ //TODO 做一些数据校验,如唯一约束
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 校验并批量删除员工管理信息
|
|
|
+ *
|
|
|
+ * @param ids 待删除的主键集合
|
|
|
+ * @param isValid 是否进行有效性校验
|
|
|
+ * @return 是否删除成功
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
|
|
+ if(isValid){
|
|
|
+ //TODO 做一些业务上的校验,判断是否需要校验
|
|
|
+ }
|
|
|
+ return baseMapper.deleteByIds(ids) > 0;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 员工申请审核
|
|
|
+ *
|
|
|
+ * @param bo
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Boolean examineStaff(StaffManageBo bo) {
|
|
|
+ StaffManage examineStaffManage = MapstructUtils.convert(bo, StaffManage.class);
|
|
|
+ //判断是否审核通过
|
|
|
+ if (TWO.equals(examineStaffManage.getExamine())) {
|
|
|
+ SysUserBo sysUser = new SysUserBo();
|
|
|
+ if (TenantHelper.isEnable()) {
|
|
|
+ //把租户id更新到sys_user表/sys_user_tenant表中
|
|
|
+ sysUser.setTenantId(examineStaffManage.getTenantId());
|
|
|
+ sysUserService.updateUserById(sysUser);
|
|
|
+ SysUserTenant sysUserTenant = new SysUserTenant();
|
|
|
+ sysUserTenant.setUserId(examineStaffManage.getUserId());
|
|
|
+ sysUserTenant.setTenantId(examineStaffManage.getTenantId());
|
|
|
+ sysUserTenantMapper.insert(sysUserTenant);
|
|
|
+ }
|
|
|
+ //组装sysUser
|
|
|
+ //给该userId赋予角色
|
|
|
+ // 新增用户与角色管理
|
|
|
+ sysUser.setUserId(bo.getUserId());
|
|
|
+ //根据权限字符去查询角色id
|
|
|
+ Long[] roles;
|
|
|
+ SysRoleVo sysRoleVo = sysRoleMapper.selectVoOne(new LambdaQueryWrapper<SysRole>().eq(SysRole::getRoleKey, examineStaffManage.getStaffCategory()));
|
|
|
+ if (sysRoleVo != null) {
|
|
|
+ roles = new Long[]{sysRoleVo.getRoleId()};
|
|
|
+ sysUser.setRoleIds(roles);
|
|
|
+ }
|
|
|
+ sysUserService.insertUserRole(sysUser, false);
|
|
|
+ } else {
|
|
|
+ return baseMapper.updateById(examineStaffManage) > 0;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+}
|