企业管理-员工信息

This commit is contained in:
xiao-fajia 2024-08-13 10:40:22 +08:00
parent 5653726bd2
commit d6d271edda
20 changed files with 529 additions and 164 deletions

View File

@ -33,4 +33,6 @@ public class BaseConstants {
public static final String LABEL_TYPE = "default";
/** 唯一推广码生成长度 */
public static final Integer UNIQUE_CODE_LEN = 6;
/**企业功能标识*/
public static final String FUNC_COMPANY = "company";
}

View File

@ -7,5 +7,6 @@ public interface CommonErrorCodeConstants extends ErrorCodeConstants {
/** 企业管理-员工管理 */
ErrorCode UNIQUE_CODE_CREATE_REPEAT = new ErrorCode(2_002_000_000, "唯一推广码生成失败");
ErrorCode STAFF_CHANGE_CREATE_REPEAT = new ErrorCode(2_002_000_001, "交出或接收员工已有交接记录");
ErrorCode STAFF_CHANGE_CREATE_REPEAT = new ErrorCode(2_002_000_001, "该员工工作已交接");
ErrorCode STAFF_NOT_CHANGE = new ErrorCode(2_002_000_003, "该员工还有工作未交接,不可删除");
}

View File

@ -17,5 +17,6 @@ public class DictBaseConstants {
public static final String DICT_SIGN_TYPE = "cus_sign_type";
/**性别*/
public static final String DICT_SYS_USER_SEX = "system_user_sex";
/**学历*/
public static final String COMPANY_STAFF_EDU = "company_staff_edu";
}

View File

@ -1,10 +1,12 @@
package cn.iocoder.yudao.module.staff.controller.admin;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.staff.entity.CompanyStaff;
import cn.iocoder.yudao.module.staff.entity.CompanyStaffChange;
import cn.iocoder.yudao.module.staff.service.CompanyStaffChangeService;
import cn.iocoder.yudao.module.staff.vo.CompanyStaffChangeReqVO;
import cn.iocoder.yudao.module.staff.vo.CompanyStaffChangeRespVO;
import cn.iocoder.yudao.module.staff.vo.CompanyStaffRespVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
@ -12,7 +14,6 @@ import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@ -30,6 +31,12 @@ public class CompanyStaffChangeController {
@Resource
private CompanyStaffChangeService staffChangeService;
/**
* 创建交接信息
* @author 小李
* @date 14:30 2024/8/12
* @param staffChangeRespVO 交接双方
**/
@PostMapping("/create")
@Operation(summary = "创建企业管理-员工交接表信息")
@PreAuthorize("@ss.hasPermission('company:staff:change')")
@ -39,15 +46,19 @@ public class CompanyStaffChangeController {
}
/**
* 查询交接双方信息
* @author 小李
* @date 18:26 2024/8/8
* @param id 接收方员工ID
**/
@GetMapping("/changeItem")
* @date 18:56 2024/8/12
* @param staffChangeReqVO 查询条件对象
* @param pageNo 页码
* @param pageSize 条数
**/
@GetMapping("/page")
@Operation(summary = "查询企业管理-员工交接表信息及交接双方")
@PreAuthorize("@ss.hasPermission('company:staff:query')")
public CommonResult<CompanyStaffChangeRespVO> getChangeStaff(@RequestParam("id") String id){
return success(staffChangeService.getChangeStaff(id));
@PreAuthorize("@ss.hasPermission('company:staffChange:query')")
public CommonResult<IPage<?>> getStaffChangePage(CompanyStaffChangeReqVO staffChangeReqVO,
@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize){
Page<CompanyStaffChange> page = new Page<>(pageNo, pageSize);
return success(staffChangeService.getStaffChangePage(staffChangeReqVO, page));
}
}

View File

@ -2,19 +2,18 @@ package cn.iocoder.yudao.module.staff.controller.admin;
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.module.label.entity.Label;
import cn.iocoder.yudao.module.staff.entity.CompanyStaff;
import cn.iocoder.yudao.module.staff.service.CompanyStaffService;
import cn.iocoder.yudao.module.staff.vo.CompanyStaffReqVO;
import cn.iocoder.yudao.module.staff.vo.CompanyStaffRespVO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.ibatis.annotations.Param;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
@ -31,9 +30,10 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
/**
* 企业管理-员工信息表 控制层
*
* @author 小李
* @date 17:14 2024/8/6
**/
**/
@RestController
@RequestMapping("/company/staff")
@Tag(name = "管理后台 - 企业管理 - 员工管理")
@ -45,28 +45,30 @@ public class CompanyStaffController {
/**
* 分页查询
*
* @param pageReqVO 查询条件对象
* @param pageNo 页码
* @param pageSize 条数
* @author 小李
* @date 17:19 2024/8/6
* @param pageReqVO 查询条件对象
* @param pageNo 页码
* @param pageSize 条数
**/
**/
@GetMapping("/page")
@Operation(summary = "获得企业管理-员工信息表信息分页")
@PreAuthorize("@ss.hasPermission('company:staff:query')")
public CommonResult<IPage<?>> getCompanyStaffPage(CompanyStaffReqVO pageReqVO,
@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
Page<CompanyStaff> page = new Page<>(pageNo, pageSize);
return success(staffService.queryListPage(pageReqVO, page));
}
/**
* 新增员工
*
* @param staffRespVO 员工对象
* @author 小李
* @date 17:20 2024/8/6
* @param staffRespVO 员工对象
**/
**/
@PostMapping("/create")
@Operation(summary = "创建企业管理-员工信息表信息")
@PreAuthorize("@ss.hasPermission('company:staff:create')")
@ -77,10 +79,11 @@ public class CompanyStaffController {
/**
* 修改员工
*
* @param staffRespVO 员工对象
* @author 小李
* @date 17:24 2024/8/6
* @param staffRespVO 员工对象
**/
**/
@PutMapping("/update")
@Operation(summary = "更新企业管理-员工信息表信息")
@PreAuthorize("@ss.hasPermission('company:staff:update')")
@ -91,10 +94,11 @@ public class CompanyStaffController {
/**
* 删除员工
*
* @param id 员工id
* @author 小李
* @date 17:28 2024/8/6
* @param id 员工id
**/
**/
@DeleteMapping("/delete")
@Operation(summary = "删除企业管理-员工信息表信息")
@Parameter(name = "id", description = "编号", required = true)
@ -106,10 +110,11 @@ public class CompanyStaffController {
/**
* 查询员工
*
* @param id
* @author 小李
* @date 17:59 2024/8/6
* @param id
**/
**/
@GetMapping("/get")
@Operation(summary = "获得企业管理-员工信息表信息")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@ -121,44 +126,71 @@ public class CompanyStaffController {
/**
* 导出员工信息表
*
* @param pageReqVO 查询条件--暂时导出所有
* @param response 响应体
* @author 小李
* @date 18:01 2024/8/6
* @param pageReqVO 查询条件--暂时导出所有
* @param response 响应体
**/
**/
@GetMapping("/export-excel")
@Operation(summary = "导出企业管理-员工信息表 Excel")
@PreAuthorize("@ss.hasPermission('company:staff:export')")
@ApiAccessLog(operateType = EXPORT)
public void exportCompanyStaffExcel(CompanyStaffReqVO pageReqVO,
HttpServletResponse response) throws IOException {
HttpServletResponse response) throws IOException {
List<CompanyStaff> list = staffService.list();
// 导出 Excel
Map<Integer, Integer> columnWidthMap = new HashMap<>();
// 第一列的索引是0宽度设置为20个字符宽
columnWidthMap.put(9, 20);
columnWidthMap.put(10, 20);
ExcelUtils.write(response, "企业信息表.xls", "数据", CompanyStaff.class, list,columnWidthMap);
ExcelUtils.write(response, "企业信息表.xls", "数据", CompanyStaff.class, list, columnWidthMap);
}
/**
* 获取当前功能的标签
*
* @author 小李
* @date 14:59 2024/8/7
**/
**/
@GetMapping("/labels")
public CommonResult<List<Label>> getLabels(){
public CommonResult<List<Label>> getLabels() {
return success(staffService.getLabels());
}
/**
* 获取当前登录用户部门下所有员工信息
*
* @author 小李
* @date 15:54 2024/8/8
**/
**/
@GetMapping("/list")
public CommonResult<List<CompanyStaff>> getStaffList(){
public CommonResult<List<CompanyStaff>> getStaffList() {
return success(staffService.getStaffList());
}
/**
* 验证工号是否重复
*
* @param workNo 输入的工号
* @author 小李
* @date 14:03 2024/8/9
**/
@GetMapping("/checkWorkNo")
public CommonResult<Boolean> checkWorkNo(@RequestParam("workNo") String workNo) {
return success(staffService.checkWorkNo(workNo));
}
/**
* 重置员工登录密码
*
* @param staffRespVO 员工对象
* @author 小李
* @date 16:21 2024/8/9
**/
@PostMapping("/resetPassword")
public CommonResult resetPassword(@RequestBody CompanyStaffRespVO staffRespVO) {
staffService.resetPassword(staffRespVO);
return CommonResult.ok();
}
}

View File

@ -1,6 +1,8 @@
package cn.iocoder.yudao.module.staff.entity;
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
import cn.iocoder.yudao.framework.tenant.core.db.TenantBaseDO;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
@ -15,6 +17,8 @@ import org.springframework.format.annotation.DateTimeFormat;
import java.math.BigDecimal;
import java.util.Date;
import static cn.iocoder.yudao.common.DictBaseConstants.*;
/**
* 企业管理-员工信息实体
* @author 小李
@ -51,7 +55,8 @@ public class CompanyStaff extends TenantBaseDO {
private String tel;
/** 性别 */
@ExcelProperty("性别")
@ExcelProperty(value = "性别", converter = DictConvert.class)
@DictFormat(DICT_SYS_USER_SEX)
private String sex;
/** 家庭住址 */
@ -65,7 +70,7 @@ public class CompanyStaff extends TenantBaseDO {
private Date workDate;
/** 工龄 */
@ExcelProperty("工龄")
@ExcelProperty("工龄(年)")
private BigDecimal workYear;
/** 入职日期 */
@ -75,11 +80,12 @@ public class CompanyStaff extends TenantBaseDO {
private Date joinedDate;
/** 司龄 */
@ExcelProperty("司龄")
@ExcelProperty("司龄(年)")
private BigDecimal joinedYear;
/** 学历 */
@ExcelProperty("学历")
@ExcelProperty(value = "学历", converter = DictConvert.class)
@DictFormat(COMPANY_STAFF_EDU)
private String education;
/** 个人简介 */

View File

@ -32,8 +32,8 @@ public class CompanyStaffChange extends TenantBaseDO {
private Long newUserId;
/** 交接时间 */
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern="yyyy-MM-dd",timezone="GMT+8")
@DateTimeFormat(pattern="yyyy-MM-dd")
private Date changeTime;
/** 附件urlsinfra_file表中的url多个英文逗号拼接 */

View File

@ -1,8 +1,13 @@
package cn.iocoder.yudao.module.staff.mapper;
import cn.iocoder.yudao.module.staff.entity.CompanyStaffChange;
import cn.iocoder.yudao.module.staff.vo.CompanyStaffChangeReqVO;
import cn.iocoder.yudao.module.staff.vo.CompanyStaffChangeRespVO;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
/**
* 企业管理-员工交接记录
@ -11,4 +16,7 @@ import org.apache.ibatis.annotations.Mapper;
**/
@Mapper
public interface CompanyStaffChangeMapper extends BaseMapper<CompanyStaffChange> {
IPage<CompanyStaffChangeRespVO> getStaffChangePage(@Param("map") CompanyStaffChangeReqVO staffChangeReqVO, Page<CompanyStaffChange> page);
}

View File

@ -1,11 +1,12 @@
package cn.iocoder.yudao.module.staff.service;
import cn.iocoder.yudao.module.staff.entity.CompanyStaffChange;
import cn.iocoder.yudao.module.staff.vo.CompanyStaffChangeReqVO;
import cn.iocoder.yudao.module.staff.vo.CompanyStaffChangeRespVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List;
/**
* 企业管理-员工交接记录 接口
* @author 小李
@ -22,10 +23,17 @@ public interface CompanyStaffChangeService extends IService<CompanyStaffChange>
void createChangeStaff(CompanyStaffChangeRespVO staffChangeRespVO);
/**
* 查询交接双方信息
* @author 小李
* @date 18:26 2024/8/8
* @param id 接收方员工ID
* @date 19:00 2024/8/12
* @param staffChangeReqVO 分页对象
**/
IPage<CompanyStaffChangeRespVO> getStaffChangePage(CompanyStaffChangeReqVO staffChangeReqVO, Page<CompanyStaffChange> page);
/**
* 判断交出方工作是否已交接
* @author 小李
* @date 18:02 2024/8/12
* @param userId 交出方ID
**/
CompanyStaffChangeRespVO getChangeStaff(String id);
Boolean checkChangeStatus(Long userId);
}

View File

@ -71,4 +71,20 @@ public interface CompanyStaffService extends IService<CompanyStaff> {
* @date 15:54 2024/8/8
**/
List<CompanyStaff> getStaffList();
/**
* 重置员工登录密码
* @author 小李
* @date 16:21 2024/8/9
* @param staffRespVO 员工对象
**/
void resetPassword(CompanyStaffRespVO staffRespVO);
/**
* 验证工号是否重复
* @author 小李
* @date 14:03 2024/8/9
* @param workNo 输入的工号
**/
Boolean checkWorkNo(String workNo);
}

View File

@ -11,11 +11,10 @@ import com.baomidou.mybatisplus.extension.service.IService;
public interface UniqueCodeService extends IService<UniqueCode> {
/**
* 新增唯一推广码
* 生成唯一推广码
* @author 小李
* @date 9:59 2024/8/8
* @param uniqueCode
*
* @return*/
int insertUniqueCode(String uniqueCode);
* @return 可使用推广码
**/
String createUniqueCode();
}

View File

@ -1,6 +1,5 @@
package cn.iocoder.yudao.module.staff.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.iocoder.yudao.common.CommonErrorCodeConstants;
import cn.iocoder.yudao.module.staff.entity.CompanyStaff;
@ -8,13 +7,20 @@ import cn.iocoder.yudao.module.staff.entity.CompanyStaffChange;
import cn.iocoder.yudao.module.staff.mapper.CompanyStaffChangeMapper;
import cn.iocoder.yudao.module.staff.service.CompanyStaffChangeService;
import cn.iocoder.yudao.module.staff.service.CompanyStaffService;
import cn.iocoder.yudao.module.staff.vo.CompanyStaffChangeReqVO;
import cn.iocoder.yudao.module.staff.vo.CompanyStaffChangeRespVO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
/**
@ -36,14 +42,12 @@ public class CompanyStaffChangeServiceImpl extends ServiceImpl<CompanyStaffChang
* @author 小李
* @date 16:15 2024/8/8
**/
@Override
@DSTransactional
public void createChangeStaff(CompanyStaffChangeRespVO staffChangeRespVO) {
// 检查是否已有相同的交接记录或交出方已经交出或接收方已接收其他工作
CompanyStaffChange staffChange = baseMapper.selectOne(new QueryWrapper<CompanyStaffChange>().and(itme -> {
itme.eq("old_user_id", staffChangeRespVO.getOldUserId())
.eq("new_user_id", staffChangeRespVO.getNewUserId());
}).or().eq("old_user_id", staffChangeRespVO.getOldUserId())
.or().eq("new_user_id", staffChangeRespVO.getNewUserId()));
if (ObjectUtil.isNotEmpty(staffChange)) {
// 确定交出方目前有没有工作可以交接
Boolean flag = checkChangeStatus(staffChangeRespVO.getOldUserId());
if (flag) {
throw exception(CommonErrorCodeConstants.STAFF_CHANGE_CREATE_REPEAT);
}
baseMapper.insert(staffChangeRespVO);
@ -51,33 +55,65 @@ public class CompanyStaffChangeServiceImpl extends ServiceImpl<CompanyStaffChang
}
/**
* 查询交接双方信息
*
* @param id 接收方员工ID
* @param staffChangeReqVO 分页对象
* @author 小李
* @date 18:26 2024/8/8
* @date 19:00 2024/8/12
**/
@Override
public CompanyStaffChangeRespVO getChangeStaff(String id) {
/** 构造返回对象 */
CompanyStaffChangeRespVO result = null;
// 1 根据当前ID获取员工记录
CompanyStaff staff = staffService.getOne(new QueryWrapper<CompanyStaff>().eq("id", id));
// 2 根据获取的员工信息中的userId获取交接记录
CompanyStaffChange staffChange = baseMapper.selectOne(new QueryWrapper<CompanyStaffChange>()
.eq("new_user_id", staff.getUserId())
.or()
.eq("old_user_id", staff.getUserId())
);
if (ObjectUtil.isNotEmpty(staffChange)) {
result = new CompanyStaffChangeRespVO();
BeanUtil.copyProperties(staffChange, result);
// 3 根据交接记录中新老员工的userId查新老员工信息
CompanyStaff oldStaff = staffService.getOne(new QueryWrapper<CompanyStaff>().eq("user_id", staffChange.getOldUserId()));
CompanyStaff newStaff = staffService.getOne(new QueryWrapper<CompanyStaff>().eq("user_id", staffChange.getNewUserId()));
result.setNewStaff(newStaff);
result.setOldStaff(oldStaff);
public IPage<CompanyStaffChangeRespVO> getStaffChangePage(CompanyStaffChangeReqVO staffChangeReqVO, Page<CompanyStaffChange> page) {
// 如果用户选择了按交接类型搜索交出接收那一定要保证员工姓名工号电话有一个不为空才行不然没有参照
if (ObjectUtil.isNotEmpty(staffChangeReqVO.getChangeType()) &&
(ObjectUtil.isNotEmpty(staffChangeReqVO.getName()) ||
ObjectUtil.isNotEmpty(staffChangeReqVO.getWorkNo()) ||
ObjectUtil.isNotEmpty(staffChangeReqVO.getTel())
)
) {
// 根据不为空的那个条件去查员工的userId
List<CompanyStaff> list = null;
if (ObjectUtil.isNotEmpty(staffChangeReqVO.getName())){
list = staffService.list(new LambdaQueryWrapper<CompanyStaff>()
.like(CompanyStaff::getName, staffChangeReqVO.getName())
);
}else if (ObjectUtil.isNotEmpty(staffChangeReqVO.getWorkNo())){
list = staffService.list(new LambdaQueryWrapper<CompanyStaff>()
.like(CompanyStaff::getWorkNo, staffChangeReqVO.getWorkNo())
);
}else if (ObjectUtil.isNotEmpty(staffChangeReqVO.getTel())){
list = staffService.list(new LambdaQueryWrapper<CompanyStaff>()
.like(CompanyStaff::getTel, staffChangeReqVO.getTel())
);
}
// 如果查到了结果才处理没查到不管
if (ObjectUtil.isNotEmpty(list)){
List<Long> userIds = list.stream().map(item -> item.getUserId()).collect(Collectors.toList());
if (staffChangeReqVO.getChangeType().equals("0")){
staffChangeReqVO.setOldUserIds(userIds);
}else{
staffChangeReqVO.setNewUserIds(userIds);
}
}
}
return result;
return baseMapper.getStaffChangePage(staffChangeReqVO, page);
}
/**
* 判断交出方工作是否已交接
*
* @param userId 交出方ID
* @author 小李
* @date 18:02 2024/8/12
**/
@Override
public Boolean checkChangeStatus(Long userId) {
// 获取该员工的最新一条记录
CompanyStaffChange staffChange = baseMapper.selectOne(new LambdaQueryWrapper<CompanyStaffChange>()
.eq(CompanyStaffChange::getOldUserId, userId)
.or()
.eq(CompanyStaffChange::getNewUserId, userId)
.orderByDesc(CompanyStaffChange::getCreateTime)
.last("limit 1")
);
// 如果为空或者最后一次相关记录他是交出方那就返回true代表他交接了工作没有工作可以交
return ObjectUtil.isNotEmpty(staffChange) && staffChange.getOldUserId().equals(userId);
}
}

View File

@ -2,26 +2,25 @@ package cn.iocoder.yudao.module.staff.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.RandomUtil;
import cn.iocoder.yudao.common.BaseConstants;
import cn.iocoder.yudao.common.CommonErrorCodeConstants;
import cn.iocoder.yudao.framework.common.util.io.FileUtils;
import cn.iocoder.yudao.framework.security.core.LoginUser;
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
import cn.iocoder.yudao.module.company.entity.Company;
import cn.iocoder.yudao.module.company.service.CompanyService;
import cn.iocoder.yudao.module.infra.api.file.FileApi;
import cn.iocoder.yudao.module.staff.entity.UniqueCode;
import cn.iocoder.yudao.module.staff.service.UniqueCodeService;
import cn.iocoder.yudao.module.label.entity.BusiLabel;
import cn.iocoder.yudao.module.label.entity.Label;
import cn.iocoder.yudao.module.label.service.BusiLabelService;
import cn.iocoder.yudao.module.label.service.LabelService;
import cn.iocoder.yudao.module.staff.entity.CompanyStaff;
import cn.iocoder.yudao.module.staff.entity.CompanyStaffChange;
import cn.iocoder.yudao.module.staff.mapper.CompanyStaffMapper;
import cn.iocoder.yudao.module.staff.service.CompanyStaffChangeService;
import cn.iocoder.yudao.module.staff.service.CompanyStaffService;
import cn.iocoder.yudao.module.staff.service.UniqueCodeService;
import cn.iocoder.yudao.module.staff.vo.CompanyStaffReqVO;
import cn.iocoder.yudao.module.staff.vo.CompanyStaffRespVO;
import cn.iocoder.yudao.module.system.api.dept.DeptApi;
import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
import cn.iocoder.yudao.module.system.api.user.dto.UserDTO;
@ -36,7 +35,6 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
@ -67,6 +65,12 @@ public class CompanyStaffServiceImpl extends ServiceImpl<CompanyStaffMapper, Com
@Resource
private UniqueCodeService uniqueCodeService;
@Resource
private DeptApi deptApi;
@Resource
private CompanyStaffChangeService staffChangeService;
/**
* 获得企业管理-员工信息表分页
*
@ -90,24 +94,24 @@ public class CompanyStaffServiceImpl extends ServiceImpl<CompanyStaffMapper, Com
@Override
@DSTransactional
public void saveStaff(CompanyStaffRespVO staffRespVO) {
/** 获取当前登录用户的信息 */
LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
AdminUserRespDTO user = adminUserApi.getUser(loginUser.getId());
// 获取当前登录用户的详细信息
AdminUserRespDTO loginUser = getLoginUser();
/** 创建UserDTO用于给sys_user插入数据 */
/* 创建UserDTO用于给sys_user插入数据 */
UserDTO userDTO = new UserDTO();
userDTO.setUsername(staffRespVO.getLoginAccount());
userDTO.setPassword(staffRespVO.getPassword());
userDTO.setNickname(staffRespVO.getName());
userDTO.setDeptId(user.getDeptId());
userDTO.setDeptId(loginUser.getDeptId());
userDTO.setMobile(staffRespVO.getTel());
userDTO.setSex(staffRespVO.getSex());
// 获取sys_users中刚插入记录ID给准备添加的员工
Long userId = adminUserApi.createUser(userDTO);
staffRespVO.setUserId(userId);
// 设置新增员工部门
staffRespVO.setDeptId(user.getDeptId());
staffRespVO.setDeptId(loginUser.getDeptId());
/** 插入标签库 */
/* 插入标签库 */
if (ObjectUtil.isNotEmpty(staffRespVO.getLabelsArray())) {
// 1 获取标签库中的存在的数据
List<Label> labels = getLabelsByLabelName(staffRespVO.getLabelsArray());
@ -123,31 +127,21 @@ public class CompanyStaffServiceImpl extends ServiceImpl<CompanyStaffMapper, Com
}
}
/** 插入员工库 */
/* 插入员工库 */
// 1 获取当前登录用户的企业信息给添加的员工
Company company = companyService.getOne(new QueryWrapper<Company>().eq("mobile_phone", user.getMobile()));
DeptRespDTO loginDept = getLoginDept(loginUser.getDeptId());
Company company = getLoginCompany(loginDept.getName());
staffRespVO.setCorpId(company.getId());
// 2 生成唯一推广码
int count = 0;
// 3 生成时判断是否重复重复就重新生成最多生成6次
while (true) {
// 重复生成和长度一样的次数还是重复就抛异常
if (count == BaseConstants.UNIQUE_CODE_LEN) {
throw exception(CommonErrorCodeConstants.UNIQUE_CODE_CREATE_REPEAT);
}
String code = RandomUtil.randomStringUpper(BaseConstants.UNIQUE_CODE_LEN);
// 直接新增唯一推码 新增成功就是可以用反之就是重复
int flag = uniqueCodeService.insertUniqueCode(code);
if (flag != 0) {
staffRespVO.setUniqueCode(code);
break;
}
count++;
String uniqueCode = uniqueCodeService.createUniqueCode();
if (!ObjectUtil.isNotEmpty(uniqueCode)){
throw exception(CommonErrorCodeConstants.UNIQUE_CODE_CREATE_REPEAT);
}
staffRespVO.setUniqueCode(uniqueCode);
// 3 保存员工信息到数据库
this.save(staffRespVO);
/** 插入标签到业务标签表 */
/* 插入标签到业务标签表 */
if (ObjectUtil.isNotEmpty(staffRespVO.getLabelsArray())) {
// 1 获取所有标签信息
List<Label> labels = getLabelsByLabelName(staffRespVO.getLabelsArray());
@ -167,9 +161,9 @@ public class CompanyStaffServiceImpl extends ServiceImpl<CompanyStaffMapper, Com
@Override
@DSTransactional
public void updateStaff(CompanyStaffRespVO staffRespVO) {
/** 修改标签 */
/* 修改标签 */
if (ObjectUtil.isNotEmpty(staffRespVO.getLabelsArray())) {
/** 检查是否需要新增标签 */
/* 检查是否需要新增标签 */
// 1 获取标签
List<Label> labels = getLabelsByLabelName(staffRespVO.getLabelsArray());
List<String> oldLabelNames = labels.stream().map(item -> item.getLabelName()).collect(Collectors.toList());
@ -181,7 +175,7 @@ public class CompanyStaffServiceImpl extends ServiceImpl<CompanyStaffMapper, Com
labelService.saveBatch(newLabels);
}
/** 检查是否需要更新业务标签 */
/* 检查是否需要更新业务标签 */
// 1 获取业务标签表中旧数据
List<BusiLabel> busiLabels = getBusiLabelsByMainId(staffRespVO.getId());
// 2 检查是否需要更新数据, 如果有就更新
@ -203,7 +197,7 @@ public class CompanyStaffServiceImpl extends ServiceImpl<CompanyStaffMapper, Com
}
}
/** 修改员工表 */
/* 修改员工表 */
baseMapper.updateById(staffRespVO);
}
@ -217,19 +211,22 @@ public class CompanyStaffServiceImpl extends ServiceImpl<CompanyStaffMapper, Com
@Override
@DSTransactional
public void deleteStaff(String id) {
/** 获取删除记录详细信息 */
/* 获取删除记录详细信息 */
CompanyStaff staff = baseMapper.selectById(id);
/** 删除sys_users记录 */
/* 验证是否已交接工作 */
Boolean flag = staffChangeService.checkChangeStatus(staff.getUserId());
if (!flag){
throw exception(CommonErrorCodeConstants.STAFF_NOT_CHANGE);
}
/* 删除sys_users记录 */
adminUserApi.deleteUser(staff.getUserId());
/** 删除业务标签表记录 */
busiLabelService.remove(new QueryWrapper<BusiLabel>().eq("main_id", staff.getId()));
/* 删除业务标签表记录 */
busiLabelService.remove(new LambdaQueryWrapper<BusiLabel>().eq(BusiLabel::getMainId, staff.getId()));
/** 删除唯一推广码表记录 */
uniqueCodeService.remove(new QueryWrapper<UniqueCode>().eq("unique_code", staff.getUniqueCode()));
/** 删除员工表记录 */
/* 删除员工表记录 */
baseMapper.deleteById(id);
}
@ -247,7 +244,7 @@ public class CompanyStaffServiceImpl extends ServiceImpl<CompanyStaffMapper, Com
// 构建员工响应对象
CompanyStaffRespVO staffRespVO = BeanUtil.toBean(staff, CompanyStaffRespVO.class);
// 查询业务标签表中属于员工的标签
List<BusiLabel> busiLabels = busiLabelService.list(new QueryWrapper<BusiLabel>().eq("main_id", staff.getId()));
List<BusiLabel> busiLabels = busiLabelService.list(new LambdaQueryWrapper<BusiLabel>().eq(BusiLabel::getMainId, staff.getId()));
// 取出标签名给员工响应对象
if (ObjectUtil.isNotEmpty(busiLabels)) {
List<String> labelsArray = busiLabels.stream().map(item -> item.getLabelName()).collect(Collectors.toList());
@ -264,7 +261,10 @@ public class CompanyStaffServiceImpl extends ServiceImpl<CompanyStaffMapper, Com
**/
@Override
public List<Label> getLabels() {
return labelService.list(new QueryWrapper<Label>().eq("system_code", BaseConstants.COMPANY_STAFF));
return labelService.list(new LambdaQueryWrapper<Label>().and(item -> {
item.eq(Label::getSystemCode, BaseConstants.COMPANY_STAFF)
.eq(Label::getType, BaseConstants.FUNC_COMPANY);
}));
}
/**
@ -288,7 +288,7 @@ public class CompanyStaffServiceImpl extends ServiceImpl<CompanyStaffMapper, Com
* @date 11:48 2024/8/8
**/
private List<BusiLabel> getBusiLabelsByMainId(String mainId) {
return busiLabelService.list(new QueryWrapper<BusiLabel>().eq("main_id", mainId));
return busiLabelService.list(new LambdaQueryWrapper<BusiLabel>().eq(BusiLabel::getMainId, mainId));
}
/**
@ -302,8 +302,8 @@ public class CompanyStaffServiceImpl extends ServiceImpl<CompanyStaffMapper, Com
return names.stream().map(item -> {
Label label = new Label();
label.setLabelName(item);
label.setType(BaseConstants.COMPANY_SING_STAFF);
label.setLabelDesc(BaseConstants.COMPANY_SING_STAFF);
label.setType(BaseConstants.FUNC_COMPANY);
label.setLabelDesc(item);
label.setLabelType(BaseConstants.LABEL_TYPE);
label.setSystemCode(BaseConstants.COMPANY_STAFF);
return label;
@ -339,12 +339,65 @@ public class CompanyStaffServiceImpl extends ServiceImpl<CompanyStaffMapper, Com
**/
@Override
public List<CompanyStaff> getStaffList(){
// 获取当前登录用户的信息取出部门
LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
Long id = loginUser.getId();
AdminUserRespDTO user = adminUserApi.getUser(id);
Long deptId = user.getDeptId();
// 获取所有该部门下的员工信息
return baseMapper.selectList(new QueryWrapper<CompanyStaff>().eq("dept_id", deptId));
return baseMapper.selectList(new QueryWrapper<>());
}
/**
* 重置员工登录密码
* @author 小李
* @date 16:21 2024/8/9
* @param staffRespVO 员工对象
**/
public void resetPassword(CompanyStaffRespVO staffRespVO){
// 修改员工密码
adminUserApi.resetPassword(staffRespVO.getUserId(), staffRespVO.getPassword());
}
/**
* 验证工号是否重复
* @author 小李
* @date 14:03 2024/8/9
* @param workNo 输入的工号
**/
public Boolean checkWorkNo(String workNo){
// 获取当前登录用户的部门ID和企业ID
AdminUserRespDTO loginUser = getLoginUser();
DeptRespDTO loginDept = getLoginDept(loginUser.getDeptId());
Company loginCompany = getLoginCompany(loginDept.getName());
return staffMapper.selectCount(new LambdaQueryWrapper<CompanyStaff>().and(item -> {
item.eq(CompanyStaff::getWorkNo, workNo)
.eq(CompanyStaff::getDeptId, loginDept.getId())
.eq(CompanyStaff::getCorpId, loginCompany.getId());
})) == 0;
}
/**
* 获取当前登录用户的详细信息
* @author 小李
* @date 17:27 2024/8/9
**/
private AdminUserRespDTO getLoginUser(){
Long userId = SecurityFrameworkUtils.getLoginUserId();
return adminUserApi.getUser(userId);
}
/**
* 获取当前登录用户的部门详细信息
* @author 小李
* @date 17:28 2024/8/9
* @param deptId 部门ID
**/
private DeptRespDTO getLoginDept(Long deptId){
return deptApi.getDept(deptId);
}
/**
* 获取当前登录用户的企业详细信息
* @author 小李
* @date 18:03 2024/8/9
* @param corpName 企业名称
**/
private Company getLoginCompany(String corpName){
return companyService.getOne(new LambdaQueryWrapper<Company>().eq(Company::getCorpName, corpName));
}
}

View File

@ -1,5 +1,7 @@
package cn.iocoder.yudao.module.staff.service.impl;
import cn.hutool.core.util.RandomUtil;
import cn.iocoder.yudao.common.BaseConstants;
import cn.iocoder.yudao.module.staff.entity.UniqueCode;
import cn.iocoder.yudao.module.staff.mapper.UniqueCodeMapper;
import cn.iocoder.yudao.module.staff.service.UniqueCodeService;
@ -15,16 +17,23 @@ import org.springframework.stereotype.Service;
public class UniqueCodeServiceImpl extends ServiceImpl<UniqueCodeMapper, UniqueCode> implements UniqueCodeService {
/**
* 检查唯一推广码是否存在于数据库
* 生成唯一推广码
* @author 小李
* @date 9:59 2024/8/8
* @param uniqueCode
*
* @return*/
* @return 可使用推广码
**/
@Override
public int insertUniqueCode(String uniqueCode){
UniqueCode code = new UniqueCode();
code.setUniqueCode(uniqueCode);
return baseMapper.insert(code);
public String createUniqueCode(){
int count = 0;
while (true){
if (count >= BaseConstants.UNIQUE_CODE_LEN) return null;
String result = RandomUtil.randomStringUpper(BaseConstants.UNIQUE_CODE_LEN);
UniqueCode uniqueCode = new UniqueCode();
uniqueCode.setUniqueCode(result);
if (baseMapper.insert(uniqueCode) > 0){
return result;
}
count++;
}
}
}

View File

@ -1,7 +1,14 @@
package cn.iocoder.yudao.module.staff.vo;
import cn.iocoder.yudao.module.staff.entity.CompanyStaffChange;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
import java.util.List;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
/**
* 企业管理-员工交接记录VO
@ -10,4 +17,26 @@ import lombok.Data;
**/
@Data
public class CompanyStaffChangeReqVO extends CompanyStaffChange {
/** 搜索用员工姓名 */
private String name;
/** 搜索用员工工号 */
private String workNo;
/** 搜索用员工电话 */
private String tel;
@Schema(description = "工作交接查询范围")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private Date[] changeTimeArray;
/** 搜索用交接类型 */
private String changeType;
/** 搜索用oldUserIds */
private List<Long> oldUserIds;
/** 搜索用newUserIds */
private List<Long> newUserIds;
}

View File

@ -3,4 +3,115 @@
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.iocoder.yudao.module.staff.mapper.CompanyStaffChangeMapper">
<resultMap id="BaseResultMap" type="cn.iocoder.yudao.module.staff.vo.CompanyStaffChangeRespVO">
<id property="id" column="csc_id" jdbcType="VARCHAR"/>
<result property="oldUserId" column="csc_old_user_id" jdbcType="BIGINT"/>
<result property="newUserId" column="csc_new_user_id" jdbcType="BIGINT"/>
<result property="changeTime" column="csc_change_time" jdbcType="TIMESTAMP"/>
<result property="fileUrls" column="csc_file_urls" jdbcType="VARCHAR"/>
<result property="remark" column="csc_remark" jdbcType="VARCHAR"/>
<association property="oldStaff" javaType="cn.iocoder.yudao.module.staff.entity.CompanyStaff">
<id property="id" column="cs_old_id" jdbcType="VARCHAR"/>
<result property="workNo" column="cs_old_work_no" jdbcType="VARCHAR"/>
<result property="name" column="cs_old_name" jdbcType="VARCHAR"/>
<result property="tel" column="cs_old_tel" jdbcType="VARCHAR"/>
<result property="sex" column="cs_old_sex" jdbcType="VARCHAR"/>
<result property="address" column="cs_old_address" jdbcType="VARCHAR"/>
<result property="workDate" column="cs_old_work_date" jdbcType="DATE"/>
<result property="workYear" column="cs_old_work_year" jdbcType="DECIMAL"/>
<result property="joinedDate" column="cs_old_joined_date" jdbcType="DATE"/>
<result property="joinedYear" column="cs_old_joined_year" jdbcType="DECIMAL"/>
<result property="education" column="cs_old_education" jdbcType="VARCHAR"/>
<result property="content" column="cs_old_content" jdbcType="VARCHAR"/>
<result property="uniqueCode" column="cs_old_unique_code" jdbcType="VARCHAR"/>
<result property="fileUrls" column="cs_old_file_urls" jdbcType="VARCHAR"/>
</association>
<association property="newStaff" javaType="cn.iocoder.yudao.module.staff.entity.CompanyStaff">
<id property="id" column="cs_new_id" jdbcType="VARCHAR"/>
<result property="workNo" column="cs_new_work_no" jdbcType="VARCHAR"/>
<result property="name" column="cs_new_name" jdbcType="VARCHAR"/>
<result property="tel" column="cs_new_tel" jdbcType="VARCHAR"/>
<result property="sex" column="cs_new_sex" jdbcType="VARCHAR"/>
<result property="address" column="cs_new_address" jdbcType="VARCHAR"/>
<result property="workDate" column="cs_new_work_date" jdbcType="DATE"/>
<result property="workYear" column="cs_new_work_year" jdbcType="DECIMAL"/>
<result property="joinedDate" column="cs_new_joined_date" jdbcType="DATE"/>
<result property="joinedYear" column="cs_new_joined_year" jdbcType="DECIMAL"/>
<result property="education" column="cs_new_education" jdbcType="VARCHAR"/>
<result property="content" column="cs_new_content" jdbcType="VARCHAR"/>
<result property="uniqueCode" column="cs_new_unique_code" jdbcType="VARCHAR"/>
<result property="fileUrls" column="cs_new_file_urls" jdbcType="VARCHAR"/>
</association>
</resultMap>
<select id="getStaffChangePage" resultMap="BaseResultMap">
SELECT
csc.id as csc_id,
csc.old_user_id as csc_old_user_id,
csc.new_user_id as csc_new_user_id,
csc.change_time as csc_change_time,
csc.file_urls as csc_file_urls,
csc.remark as csc_remark,
cs_old.id as cs_old_id,
cs_old.work_no as cs_old_work_no,
cs_old.name as cs_old_name,
cs_old.tel as cs_old_tel,
cs_old.sex as cs_old_sex,
cs_old.address as cs_old_address,
cs_old.work_date as cs_old_work_date,
cs_old.work_year as cs_old_work_year,
cs_old.joined_date as cs_old_joined_date,
cs_old.joined_year as cs_old_joined_year,
cs_old.education as cs_old_education,
cs_old.content as cs_old_content,
cs_old.unique_code as cs_old_unique_code,
cs_old.file_urls as cs_old_file_urls,
cs_new.id as cs_new_id,
cs_new.work_no as cs_new_work_no,
cs_new.name as cs_new_name,
cs_new.tel as cs_new_tel,
cs_new.sex as cs_new_sex,
cs_new.address as cs_new_address,
cs_new.work_date as cs_new_work_date,
cs_new.work_year as cs_new_work_year,
cs_new.joined_date as cs_new_joined_date,
cs_new.joined_year as cs_new_joined_year,
cs_new.education as cs_new_education,
cs_new.content as cs_new_content,
cs_new.unique_code as cs_new_unique_code,
cs_new.file_urls as cs_new_file_urls
FROM company_staff_change csc
INNER JOIN company_staff cs_old ON csc.old_user_id = cs_old.user_id
INNER JOIN company_staff cs_new ON csc.new_user_id = cs_new.user_id
where csc.deleted = '0'
<if test="map.name != null and map.name != ''">
and (cs_old.name like concat('%', #{map.name}, '%') or cs_new.name like concat('%', #{map.name}, '%'))
</if>
<if test="map.workNo != null and map.workNo != ''">
and (cs_old.work_no like concat('%', #{map.workNo}, '%') or cs_new.work_no like concat('%', #{map.workNo}, '%'))
</if>
<if test="map.tel != null and map.tel != ''">
and (cs_old.tel like concat('%', #{map.tel}, '%') or cs_new.tel like concat('%', #{map.tel}, '%'))
</if>
<if test="map.changeTimeArray != null and map.changeTimeArray.length > 0">
and (csc.changeTime between #{map.changeTimeArray[0]} and #{map.changeTimeArray[1]})
</if>
<if test="map.oldUserIds != null and map.oldUserIds.size > 0">
and csc.old_user_id in
<foreach collection="map.oldUserIds" item="userId" open="(" separator="," close=")">
#{userId}
</foreach>
</if>
<if test="map.newUserIds != null and map.newUserIds.size > 0">
and csc.new_user_id in
<foreach collection="map.newUserIds" item="userId" open="(" separator="," close=")">
#{userId}
</foreach>
</if>
order by csc.create_time desc
</select>
</mapper>

View File

@ -31,19 +31,35 @@
</resultMap>
<sql id="Base_SQL">
select
id,corp_id,user_id,
dept_id,work_no,name,
tel,sex,address,
work_date,work_year,joined_date,
joined_year,education,content,
unique_code,file_urls,tenant_id,
deleted,creator,create_time,
updater,update_time
from company_staff cs where deleted = '0'
select id,
corp_id,
user_id,
dept_id,
work_no,
name,
tel,
sex,
address,
work_date,
work_year,
joined_date,
joined_year,
education,
content,
unique_code,
file_urls,
tenant_id,
deleted,
creator,
create_time,
updater,
update_time
from company_staff cs
where deleted = '0'
</sql>
<select id="selectListPage" resultMap="BaseResultMap">
<include refid="Base_SQL" />
<include refid="Base_SQL"/>
<if test="map.name != null and map.name != ''">
and cs.name like concat('%', #{map.name}, '%')
</if>
@ -77,5 +93,6 @@
<if test="map.joinedDateArray.length > 0">
and cs.joined_date between #{map.joinedDateArray[0]} and #{map.joinedDateArray[1]}
</if>
order by create_time desc
</select>
</mapper>

View File

@ -112,4 +112,13 @@ public interface AdminUserApi {
*/
void validateUserList(Collection<Long> ids);
/**
* 重置密码
* @author 小李
* @date 16:39 2024/8/9
* @param id 用户ID
* @param password 新密码
**/
void resetPassword(Long id, String password);
}

View File

@ -34,4 +34,9 @@ public class UserDTO {
*/
private String password;
/**
* 用户性别
**/
private String sex;
}

View File

@ -126,4 +126,16 @@ public class AdminUserApiImpl implements AdminUserApi {
userService.validateUserList(ids);
}
/**
* 重置密码
* @author 小李
* @date 16:39 2024/8/9
* @param id 用户ID
* @param password 新密码
**/
@Override
public void resetPassword(Long id, String password){
userService.updateUserPassword(id, password);
}
}