feat:增加职位管理功能

This commit is contained in:
曾文豪
2023-03-28 16:40:54 +08:00
parent c446ee8f75
commit af70808da6
19 changed files with 950 additions and 0 deletions

View File

@@ -0,0 +1,135 @@
package com.tiesheng.core.controller;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tiesheng.core.pojos.dao.CoreJob;
import com.tiesheng.core.pojos.dao.CoreJobPoint;
import com.tiesheng.core.pojos.dto.IdDTO;
import com.tiesheng.core.pojos.dto.PageDTO;
import com.tiesheng.core.pojos.dto.job.JobUpdateDTO;
import com.tiesheng.core.pojos.dto.job.JobUpdateRxDTO;
import com.tiesheng.core.pojos.dto.job.JobUserAssignDTO;
import com.tiesheng.core.pojos.dto.job.JobUserOwner;
import com.tiesheng.core.service.JobService;
import com.tiesheng.login.config.token.TsTokenConfig;
import com.tiesheng.util.exception.ApiException;
import com.tiesheng.util.pojos.ApiResp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.List;
/**
* @author hao
*/
@RestController
@RequestMapping("/job")
public class JobController {
@Autowired
JobService jobService;
/**
* 获取职位列表
*
* @return
*/
@GetMapping("/list")
public ApiResp<List<CoreJob>> list(PageDTO dto) {
QueryWrapper<CoreJob> queryWrapper = new QueryWrapper<CoreJob>().eq("is_deleted", 0);
dto.likeColumns(queryWrapper, "name");
List<CoreJob> jobList = jobService.list(queryWrapper);
return ApiResp.respOK(jobList);
}
/**
* 添加、编辑职位
*
* @return
*/
@PostMapping("/update")
public ApiResp<String> update(@Valid @RequestBody JobUpdateDTO dto) {
CoreJob job = BeanUtil.copyProperties(dto, CoreJob.class);
if (!StrUtil.isEmpty(job.getId())) {
CoreJob byId = jobService.getById(job.getId());
if (byId != null && byId.getIsSystem() == 1) {
throw new ApiException("系统配置,无法编辑");
}
}
jobService.saveOrUpdate(job);
return ApiResp.respOK("");
}
/**
* 获取职位功能点
*
* @return
*/
@GetMapping("/point/list")
public ApiResp<List<CoreJobPoint>> pointList() {
List<CoreJobPoint> pointList = jobService.getJobPointMapper().selectList(new QueryWrapper<CoreJobPoint>()
.eq("is_deleted", 0)
);
return ApiResp.respOK(pointList);
}
/**
* 获取关系
*
* @param dto
* @return
*/
@GetMapping("/point/rx")
public ApiResp<List<String>> pointRx(@Valid IdDTO dto) {
List<String> list = jobService.getJobPointMapper().getJobRx(dto.getId());
return ApiResp.respOK(list);
}
/**
* 更新职位关系
*
* @return
*/
@PostMapping("/point/rx")
public ApiResp<String> updateJobRx(@Valid @RequestBody JobUpdateRxDTO dto) {
jobService.updateJobRx(dto.getJobId(), StrUtil.split(dto.getPoints(), ","));
return ApiResp.respOK("");
}
/**
* 用户职位分配
*
* @return
*/
@PostMapping("/user/assign")
public ApiResp<String> userAssign(@Valid @RequestBody JobUserAssignDTO dto) {
jobService.userAssign(dto.getUserId(), dto.getJobId());
return ApiResp.respOK("");
}
/**
* 获取用户自己的
*
* @return
*/
@GetMapping("/user/owner")
public ApiResp<List<JobUserOwner>> userOwner() {
List<JobUserOwner> coreJobUsers = jobService.getJobUserMapper().list(TsTokenConfig.get().getId());
coreJobUsers.forEach(it -> {
List<String> list = jobService.getJobPointMapper().getJobRx(it.getJobId());
it.setPoints(list);
});
return ApiResp.respOK(coreJobUsers);
}
}

View File

@@ -0,0 +1,7 @@
package com.tiesheng.core.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tiesheng.core.pojos.dao.CoreJob;
public interface CoreJobMapper extends BaseMapper<CoreJob> {
}

View File

@@ -0,0 +1,37 @@
package com.tiesheng.core.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tiesheng.core.pojos.dao.CoreJobPoint;
import com.tiesheng.util.pojos.IdName;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface CoreJobPointMapper extends BaseMapper<CoreJobPoint> {
/**
* 清除职位的关联关系
*
* @param jobId
*/
void clearJobRx(@Param("jobId") String jobId);
/**
* 更新关联关系
*
* @param pointList
*/
void updateJobRx(@Param("list") List<IdName> pointList);
/**
* 获取关联的point
*
* @param jobId
* @return
*/
List<String> getJobRx(@Param("jobId") String jobId);
}

View File

@@ -0,0 +1,21 @@
package com.tiesheng.core.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tiesheng.core.pojos.dao.CoreJobUser;
import com.tiesheng.core.pojos.dto.job.JobUserOwner;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface CoreJobUserMapper extends BaseMapper<CoreJobUser> {
/**
* 获取指定用户的职位和功能点
*
* @param userId
* @return
*/
List<JobUserOwner> list(@Param("userId") String userId);
}

View File

@@ -0,0 +1,86 @@
package com.tiesheng.core.pojos.dao;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.tiesheng.core.pojos.DaoBase;
import java.util.Date;
/**
* 职位
*/
@TableName(value = "core_job")
public class CoreJob extends DaoBase {
/**
* 名称
*/
@TableField(value = "`name`")
private String name;
/**
* 其他说明
*/
@TableField(value = "remark")
private String remark;
/**
* 是否系统
*/
@TableField(value = "is_system")
private Integer isSystem;
/**
* 获取名称
*
* @return name - 名称
*/
public String getName() {
return name;
}
/**
* 设置名称
*
* @param name 名称
*/
public void setName(String name) {
this.name = name;
}
/**
* 获取其他说明
*
* @return remark - 其他说明
*/
public String getRemark() {
return remark;
}
/**
* 设置其他说明
*
* @param remark 其他说明
*/
public void setRemark(String remark) {
this.remark = remark;
}
/**
* 获取是否系统
*
* @return is_system - 是否系统
*/
public Integer getIsSystem() {
return isSystem;
}
/**
* 设置是否系统
*
* @param isSystem 是否系统
*/
public void setIsSystem(Integer isSystem) {
this.isSystem = isSystem;
}
}

View File

@@ -0,0 +1,86 @@
package com.tiesheng.core.pojos.dao;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.tiesheng.core.pojos.DaoBase;
import java.util.Date;
/**
* 职位-功能点
*/
@TableName(value = "core_job_point")
public class CoreJobPoint extends DaoBase {
/**
* 业务
*/
@TableField(value = "service")
private String service;
/**
* 名称
*/
@TableField(value = "`name`")
private String name;
/**
* 其他说明
*/
@TableField(value = "remark")
private String remark;
/**
* 获取业务
*
* @return service - 业务
*/
public String getService() {
return service;
}
/**
* 设置业务
*
* @param service 业务
*/
public void setService(String service) {
this.service = service;
}
/**
* 获取名称
*
* @return name - 名称
*/
public String getName() {
return name;
}
/**
* 设置名称
*
* @param name 名称
*/
public void setName(String name) {
this.name = name;
}
/**
* 获取其他说明
*
* @return remark - 其他说明
*/
public String getRemark() {
return remark;
}
/**
* 设置其他说明
*
* @param remark 其他说明
*/
public void setRemark(String remark) {
this.remark = remark;
}
}

View File

@@ -0,0 +1,62 @@
package com.tiesheng.core.pojos.dao;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.tiesheng.core.pojos.DaoBase;
import java.util.Date;
/**
* 职位-用户
*/
@TableName(value = "core_job_user")
public class CoreJobUser extends DaoBase {
/**
* 用户id
*/
@TableField(value = "user_id")
private String userId;
/**
* 用户
*/
@TableField(value = "job_id")
private String jobId;
/**
* 获取用户id
*
* @return user_id - 用户id
*/
public String getUserId() {
return userId;
}
/**
* 设置用户id
*
* @param userId 用户id
*/
public void setUserId(String userId) {
this.userId = userId;
}
/**
* 获取用户
*
* @return job_id - 用户
*/
public String getJobId() {
return jobId;
}
/**
* 设置用户
*
* @param jobId 用户
*/
public void setJobId(String jobId) {
this.jobId = jobId;
}
}

View File

@@ -0,0 +1,23 @@
package com.tiesheng.core.pojos.dto;
import javax.validation.constraints.NotEmpty;
public class IdDTO {
@NotEmpty(message = "需要ID")
private String id;
///////////////////////////////////////////////////////////////////////////
// setter\getter
///////////////////////////////////////////////////////////////////////////
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
}

View File

@@ -0,0 +1,40 @@
package com.tiesheng.core.pojos.dto.job;
import javax.validation.constraints.NotEmpty;
public class JobUpdateDTO {
private String id;
@NotEmpty(message = "请输入职位名称")
private String name;
private String remark;
///////////////////////////////////////////////////////////////////////////
// setter\getter
///////////////////////////////////////////////////////////////////////////
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark;
}
}

View File

@@ -0,0 +1,30 @@
package com.tiesheng.core.pojos.dto.job;
import javax.validation.constraints.NotEmpty;
public class JobUpdateRxDTO {
@NotEmpty(message = "请选择职位")
private String jobId;
private String points;
///////////////////////////////////////////////////////////////////////////
// setter\getter
///////////////////////////////////////////////////////////////////////////
public String getJobId() {
return jobId;
}
public void setJobId(String jobId) {
this.jobId = jobId;
}
public String getPoints() {
return points;
}
public void setPoints(String points) {
this.points = points;
}
}

View File

@@ -0,0 +1,31 @@
package com.tiesheng.core.pojos.dto.job;
import javax.validation.constraints.NotEmpty;
public class JobUserAssignDTO {
@NotEmpty(message = "请选择用户")
private String userId;
@NotEmpty(message = "请选择职位")
private String jobId;
///////////////////////////////////////////////////////////////////////////
// setter\getter
///////////////////////////////////////////////////////////////////////////
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public String getJobId() {
return jobId;
}
public void setJobId(String jobId) {
this.jobId = jobId;
}
}

View File

@@ -0,0 +1,40 @@
package com.tiesheng.core.pojos.dto.job;
import com.tiesheng.util.pojos.IdName;
import java.util.List;
public class JobUserOwner {
private String jobId;
private String jobName;
private List<String> points;
///////////////////////////////////////////////////////////////////////////
// setter\getter
///////////////////////////////////////////////////////////////////////////
public String getJobId() {
return jobId;
}
public void setJobId(String jobId) {
this.jobId = jobId;
}
public String getJobName() {
return jobName;
}
public void setJobName(String jobName) {
this.jobName = jobName;
}
public List<String> getPoints() {
return points;
}
public void setPoints(List<String> points) {
this.points = points;
}
}

View File

@@ -0,0 +1,131 @@
package com.tiesheng.core.service;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tiesheng.core.mapper.CoreJobMapper;
import com.tiesheng.core.mapper.CoreJobPointMapper;
import com.tiesheng.core.mapper.CoreJobUserMapper;
import com.tiesheng.core.pojos.dao.CoreJob;
import com.tiesheng.core.pojos.dao.CoreJobPoint;
import com.tiesheng.core.pojos.dao.CoreJobUser;
import com.tiesheng.util.pojos.IdName;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
/**
* @author hao
*/
@Service
public class JobService extends TsServiceBase<CoreJobMapper, CoreJob> {
@Autowired
CoreJobPointMapper coreJobPointMapper;
@Autowired
CoreJobUserMapper coreJobUserMapper;
public CoreJobPointMapper getJobPointMapper() {
return coreJobPointMapper;
}
public CoreJobUserMapper getJobUserMapper() {
return coreJobUserMapper;
}
/**
* 刷新职位
*
* @param name
* @param remark
* @param isSystem
*/
public void refresh(String id, String name, String remark, Integer isSystem, List<String> points) {
CoreJob coreJob = new CoreJob();
coreJob.setId(id);
coreJob.setName(name);
coreJob.setRemark(remark);
coreJob.setIsSystem(isSystem);
saveOrUpdate(coreJob);
// 增加关联关系
updateJobRx(coreJob.getId(), points);
}
/**
* 刷新功能点
*
* @param id
* @param service
* @param name
* @param remark
*/
public void refreshPoint(String id, String service, String name, String remark) {
CoreJobPoint jobPoint = new CoreJobPoint();
jobPoint.setId(id);
jobPoint.setService(service);
jobPoint.setName(name);
jobPoint.setRemark(remark);
try {
coreJobPointMapper.insert(jobPoint);
} catch (Exception e) {
coreJobPointMapper.updateById(jobPoint);
}
}
/**
* 更新关联关系
*
* @param jobId
* @param points
*/
public void updateJobRx(String jobId, List<String> points) {
List<IdName> nameList = new ArrayList<>();
for (String s : points) {
IdName id = new IdName();
id.setId(IdUtil.getSnowflakeNextIdStr());
id.setName(jobId);
id.setExtra(s);
nameList.add(id);
}
if (StrUtil.isEmpty(jobId)) {
return;
}
coreJobPointMapper.clearJobRx(jobId);
if (CollUtil.isNotEmpty(nameList)) {
coreJobPointMapper.updateJobRx(nameList);
}
}
/**
* 分配职位
*
* @param userId
* @param jobId
*/
public void userAssign(String userId, String jobId) {
CoreJobUser jobUser = coreJobUserMapper.selectOne(new QueryWrapper<CoreJobUser>()
.eq("is_deleted", 0)
.eq("user_id", userId)
.eq("job_id", jobId)
);
if (jobUser == null) {
jobUser = new CoreJobUser();
}
jobUser.setUserId(userId);
jobUser.setJobId(jobId);
if (StrUtil.isEmpty(jobUser.getId())) {
coreJobUserMapper.insert(jobUser);
} else {
coreJobUserMapper.updateById(jobUser);
}
}
}