diff --git a/src/main/java/com/ydool/common/constant/UrlConstant.java b/src/main/java/com/ydool/common/constant/UrlConstant.java index f9b2f66..eab50b0 100644 --- a/src/main/java/com/ydool/common/constant/UrlConstant.java +++ b/src/main/java/com/ydool/common/constant/UrlConstant.java @@ -26,6 +26,9 @@ public interface UrlConstant { String MENU = API + "/menu"; + + String JOB = API + "/job"; + String PERSON = API + "/person"; String EXCHANGE = API + "/exchange"; diff --git a/src/main/java/com/ydool/common/gen/Generator.java b/src/main/java/com/ydool/common/gen/Generator.java index daa5261..02d63da 100644 --- a/src/main/java/com/ydool/common/gen/Generator.java +++ b/src/main/java/com/ydool/common/gen/Generator.java @@ -27,7 +27,7 @@ public class Generator { public static void main(String[] args) { //表名 - String tableName = "t_sys_menu"; + String tableName = "t_sys_job"; //表前缀 String tablePrefix = "t_sys_"; //作者— diff --git a/src/main/java/com/ydool/system/controller/JobController.java b/src/main/java/com/ydool/system/controller/JobController.java new file mode 100644 index 0000000..55f951c --- /dev/null +++ b/src/main/java/com/ydool/system/controller/JobController.java @@ -0,0 +1,159 @@ +package com.ydool.system.controller; + +import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; +import com.github.xiaoymin.knife4j.annotations.ApiSupport; +import com.github.xiaoymin.knife4j.annotations.DynamicParameter; +import com.github.xiaoymin.knife4j.annotations.DynamicResponseParameters; +import com.ydool.common.base.BaseController; +import com.ydool.common.constant.UrlConstant; +import com.ydool.common.data.dto.AjaxResult; +import com.ydool.system.entity.Job; +import com.ydool.system.entity.Role; +import com.ydool.system.request.IdsRequest; +import com.ydool.system.request.JobRequest; +import com.ydool.system.request.RoleMenuRequest; +import com.ydool.system.request.RoleRequest; +import com.ydool.system.service.IJobService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import java.util.List; +import java.util.prefs.BackingStoreException; + +@RestController +@RequestMapping(UrlConstant.JOB) +@Api(tags = "岗位", value = "岗位") +@ApiSupport(order = 10) +public class JobController extends BaseController { + @Autowired + private IJobService jobService; + + /** + * 岗位列表 + * + * @param value + * @param column + * @param orderBy + * @param status + * @return + */ + @GetMapping(value = "list") + @ApiOperation(value = "岗位列表") + @ApiImplicitParams({ + @ApiImplicitParam(name = "current", value = "当前页", dataType = "Integer"), + @ApiImplicitParam(name = "size", value = "每页条数", dataType = "Integer"), + @ApiImplicitParam(name = "value", value = "搜索框中的内容(只支持字符串类型)"), + @ApiImplicitParam(name = "column", value = "排序字段 字段名"), + @ApiImplicitParam(name = "orderBy", value = "排序顺序 降序:desc,升序:asc"), + @ApiImplicitParam(name = "status", value = "启用状态", dataType = "Boolean"), + }) + @ApiOperationSupport( + responses = @DynamicResponseParameters(properties = { + @DynamicParameter(name = "data", dataTypeClass = Job.class) + }), + order = 1 + ) + public AjaxResult jobList(String value, + String column, + String orderBy, + Boolean status + ) { + return jobService.jobList(getPage(), value, column, orderBy, status); + } + + /** + * 岗位详情 + * + * @param id + * @return + */ + @GetMapping(value = "detail") + @ApiOperation(value = "岗位详情") + @ApiOperationSupport( + responses = @DynamicResponseParameters(properties = { + @DynamicParameter(name = "data", dataTypeClass = Job.class) + }), order = 2 + ) + @ApiImplicitParam(name = "id", value = "岗位Id") + public AjaxResult jobDetail(String id) { + return jobService.jobDetail(id); + } + + /** + * 保存岗位 + * + * @param jobRequest + * @return + */ + @PostMapping(value = "save") + @ApiOperation(value = "保存岗位") + @ApiOperationSupport(order = 3) + public AjaxResult saveJob(@RequestBody @Validated JobRequest jobRequest) { + return jobService.saveJob(jobRequest); + } + + /** + * 编辑岗位 + * + * @param id + * @param jobRequest + * @return + */ + @PutMapping(value = "edit") + @ApiOperation(value = "编辑岗位") + @ApiImplicitParam(name = "id", value = "岗位Id") + @ApiOperationSupport(order = 4) + public AjaxResult editJob(String id, @RequestBody @Validated JobRequest jobRequest) { + return jobService.editJob(id, jobRequest); + } + + /** + * 单个删除岗位 + * + * @param id + * @return + */ + @DeleteMapping(value = "remove") + @ApiOperation(value = "删除岗位") + @ApiImplicitParam(name = "id", value = "岗位Id") + @ApiOperationSupport(order = 5) + public AjaxResult removeJob(String id) { + return jobService.removeJob(id); + } + + /** + * 批量删除岗位 + * + * @param ids + * @return + */ + @PostMapping(value = "removeBatch") + @ApiOperation(value = "批量删除岗位") + @ApiOperationSupport(order = 6) + public AjaxResult removeJobs(@RequestBody @Validated IdsRequest ids) { + return jobService.removeJobs(ids); + } + + + + /** + * 岗位列表下拉框 + * + * @return + */ + @GetMapping(value = "jobs") + @ApiOperation(value = "岗位列表下拉框") + @ApiOperationSupport( + responses = @DynamicResponseParameters(properties = { + @DynamicParameter(name = "data", dataTypeClass = Job.class) + }), order = 7 + ) + public AjaxResult jobs() { + return jobService.jobs(); + } +} diff --git a/src/main/java/com/ydool/system/dto/UserDto.java b/src/main/java/com/ydool/system/dto/UserDto.java index 14dbf7b..6a18cb7 100644 --- a/src/main/java/com/ydool/system/dto/UserDto.java +++ b/src/main/java/com/ydool/system/dto/UserDto.java @@ -12,4 +12,7 @@ public class UserDto extends User { @ApiModelProperty(value = "角色名称") private String rolesName; + + @ApiModelProperty(value = "岗位名称") + private String jobName; } diff --git a/src/main/java/com/ydool/system/entity/Job.java b/src/main/java/com/ydool/system/entity/Job.java new file mode 100644 index 0000000..7c3ab3d --- /dev/null +++ b/src/main/java/com/ydool/system/entity/Job.java @@ -0,0 +1,41 @@ +package com.ydool.system.entity; +import com.baomidou.mybatisplus.annotation.TableName; +import com.ydool.common.base.BaseEntity; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; +/** + *

+ * 系统岗位 + *

+ * + * @author ljq + * @since 2023-02-08 + */ +@Data +@EqualsAndHashCode(callSuper = true) +@Accessors(chain = true) +@TableName("t_sys_job") +@ApiModel(value="Job对象", description="系统岗位") +public class Job extends BaseEntity{ + + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "岗位编码") + private String code; + + @ApiModelProperty(value = "岗位名称") + private String name; + + @ApiModelProperty(value = "排序") + private Integer sortNo; + + @ApiModelProperty(value = "启用状态") + private Boolean status; + + @ApiModelProperty(value = "备注") + private String remarks; + +} diff --git a/src/main/java/com/ydool/system/entity/User.java b/src/main/java/com/ydool/system/entity/User.java index 378d3f3..cc3f5b6 100644 --- a/src/main/java/com/ydool/system/entity/User.java +++ b/src/main/java/com/ydool/system/entity/User.java @@ -70,4 +70,7 @@ public class User extends BaseEntity{ @ApiModelProperty(value = "备注") private String remarks; + @ApiModelProperty(value = "岗位") + private String job; + } diff --git a/src/main/java/com/ydool/system/mapper/JobMapper.java b/src/main/java/com/ydool/system/mapper/JobMapper.java new file mode 100644 index 0000000..8f96485 --- /dev/null +++ b/src/main/java/com/ydool/system/mapper/JobMapper.java @@ -0,0 +1,18 @@ +package com.ydool.system.mapper; + +import com.ydool.system.entity.Job; +import com.github.yulichang.base.MPJBaseMapper; +import org.apache.ibatis.annotations.Mapper; + +/** + *

+ * 系统岗位 Mapper 接口 + *

+ * + * @author ljq + * @since 2023-02-08 + */ +@Mapper +public interface JobMapper extends MPJBaseMapper { + +} diff --git a/src/main/java/com/ydool/system/request/JobRequest.java b/src/main/java/com/ydool/system/request/JobRequest.java new file mode 100644 index 0000000..5db1666 --- /dev/null +++ b/src/main/java/com/ydool/system/request/JobRequest.java @@ -0,0 +1,29 @@ +package com.ydool.system.request; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; + +@Data +public class JobRequest { + @ApiModelProperty(value = "岗位编码") + @NotBlank(message = "岗位编码不能为空") + private String code; + + @ApiModelProperty(value = "岗位名称") + @NotBlank(message = "岗位名称不能为空") + private String name; + + @ApiModelProperty(value = "排序") + @NotNull(message = "排序不能为空") + private Integer sortNo; + + @ApiModelProperty(value = "启用状态") + @NotNull(message = "启用状态不能为空") + private Boolean status; + + @ApiModelProperty(value = "备注") + private String remarks; +} diff --git a/src/main/java/com/ydool/system/request/UserRequest.java b/src/main/java/com/ydool/system/request/UserRequest.java index f2cb8bf..2d55db3 100644 --- a/src/main/java/com/ydool/system/request/UserRequest.java +++ b/src/main/java/com/ydool/system/request/UserRequest.java @@ -36,4 +36,8 @@ public class UserRequest { @ApiModelProperty(value = "备注") private String remarks; + + @ApiModelProperty(value = "岗位") + @NotBlank(message = "岗位不能为空") + private String job; } diff --git a/src/main/java/com/ydool/system/service/IJobService.java b/src/main/java/com/ydool/system/service/IJobService.java new file mode 100644 index 0000000..fd29c07 --- /dev/null +++ b/src/main/java/com/ydool/system/service/IJobService.java @@ -0,0 +1,75 @@ +package com.ydool.system.service; + +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.ydool.common.data.dto.AjaxResult; +import com.ydool.system.request.IdsRequest; +import com.ydool.system.request.JobRequest; + +/** + *

+ * 系统岗位 服务类 + *

+ * + * @author ljq + * @since 2023-02-08 + */ +public interface IJobService { + + /** + * 保存岗位 + * @param jobRequest + * @return + */ + AjaxResult saveJob(JobRequest jobRequest); + + + /** + * 编辑岗位 + * @param id + * @param jobRequest + * @return + */ + AjaxResult editJob(String id,JobRequest jobRequest); + + /** + * 删除岗位 + * + * @param id + * @return + */ + AjaxResult removeJob(String id); + + /** + * 批量删除岗位 + * @param ids + * @return + */ + AjaxResult removeJobs(IdsRequest ids); + + /** + * 岗位详情 + * @param id + * @return + */ + AjaxResult jobDetail(String id); + + /** + * 岗位列表 + * @param page + * @param value + * @param column + * @param orderBy + * @param status + * @return + */ + AjaxResult jobList(Page page, String value, String column, String orderBy, Boolean status); + + + /** + * 岗位列表 + * @return + */ + AjaxResult jobs(); + +} + diff --git a/src/main/java/com/ydool/system/service/impl/JobServiceImpl.java b/src/main/java/com/ydool/system/service/impl/JobServiceImpl.java new file mode 100644 index 0000000..6a65f1c --- /dev/null +++ b/src/main/java/com/ydool/system/service/impl/JobServiceImpl.java @@ -0,0 +1,184 @@ +package com.ydool.system.service.impl; + +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.ArrayUtil; +import cn.hutool.core.util.ObjUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.ydool.common.base.BaseService; +import com.ydool.common.data.dto.AjaxResult; +import com.ydool.system.entity.Job; +import com.ydool.system.entity.Role; +import com.ydool.system.mapper.JobMapper; +import com.ydool.system.request.IdsRequest; +import com.ydool.system.request.JobRequest; +import com.ydool.system.service.IJobService; +import org.springframework.stereotype.Service; + +import java.util.Arrays; +import java.util.List; + +/** + *

+ * 系统岗位 服务类 + *

+ * + * @author ljq + * @since 2023-02-08 + */ +@Service +public class JobServiceImpl extends BaseService implements IJobService { + + /** + * 保存岗位 + * + * @param jobRequest + * @return + */ + @Override + public AjaxResult saveJob(JobRequest jobRequest) { + String message = checkJob("", jobRequest); + if (StrUtil.isNotBlank(message)) return AjaxResult.fail(message); + Job job = BeanUtil.copyProperties(jobRequest, Job.class); + boolean flag = save(job); + return flag ? AjaxResult.ok().msg("保存成功") : AjaxResult.fail("保存失败"); + } + + /** + * 编辑岗位 + * + * @param id + * @param jobRequest + * @return + */ + @Override + public AjaxResult editJob(String id, JobRequest jobRequest) { + if (StrUtil.isBlank(id)) return AjaxResult.fail("id不能为空"); + String message = checkJob(id, jobRequest); + if (StrUtil.isNotBlank(message)) return AjaxResult.fail(message); + Job job = getById(id); + if (ObjectUtil.isNull(job)) return AjaxResult.fail("该岗位不存在"); + BeanUtil.copyProperties(jobRequest, job); + boolean flag = updateById(job); + return flag ? AjaxResult.ok().msg("编辑成功") : AjaxResult.fail("编辑失败"); + } + + /** + * 删除岗位 + * + * @param id + * @return + */ + @Override + public AjaxResult removeJob(String id) { + if (StrUtil.isBlank(id)) return AjaxResult.fail("id不能为空"); + Job job = getById(id); + if (ObjectUtil.isNull(job)) return AjaxResult.fail("该岗位不存在"); + return removeById(id) ? AjaxResult.ok().msg("删除成功") : AjaxResult.fail("删除失败"); + } + + /** + * 批量删除岗位 + * + * @param ids + * @return + */ + @Override + public AjaxResult removeJobs(IdsRequest ids) { + String[] idList = ids.getIds(); + if (ArrayUtil.isEmpty(idList)) return AjaxResult.fail("岗位Id集合不能为空"); + List jobList = listByIds(Arrays.asList(idList)); + if (CollUtil.isEmpty(jobList)) return AjaxResult.fail("该岗位集合全部不存在"); + return removeByIds(Arrays.asList(idList)) ? AjaxResult.ok().msg("批量删除成功") : AjaxResult.fail("批量删除失败"); + + } + + /** + * 岗位详情 + * + * @param id + * @return + */ + @Override + public AjaxResult jobDetail(String id) { + if (StrUtil.isBlank(id)) return AjaxResult.fail("id不能为空"); + Job job = getById(id); + return AjaxResult.ok().data(job); + } + + /** + * 岗位列表 + * + * @param page + * @param value + * @param column + * @param orderBy + * @param status + * @return + */ + @Override + public AjaxResult jobList(Page page, String value, String column, String orderBy, Boolean status) { + QueryWrapper qw = new QueryWrapper(); + if (StrUtil.isNotBlank(value)) { + qw.lambda().like(Job::getName, value) + .or().like(Job::getRemarks, value) + .or().like(Job::getCode, value); + } + + qw.lambda().eq(ObjectUtil.isNotNull(status), Job::getStatus, status); + + if ("desc".equals(orderBy) && StrUtil.isNotBlank(column)) { + qw.orderByDesc(StrUtil.toUnderlineCase(column)); + } + + if ("asc".equals(orderBy) && StrUtil.isNotBlank(column)) { + qw.orderByAsc(StrUtil.toUnderlineCase(column)); + } + + Page pageList = page(page, qw); + + return AjaxResult.ok().data(pageList); + } + + /** + * 岗位列表 + * + * @return + */ + @Override + public AjaxResult jobs() { + List jobs = list(new QueryWrapper().lambda() + .eq(Job::getStatus, true) + ); + return AjaxResult.ok().data(jobs); + } + + /** + * 校验岗位 + * + * @param id + * @param jobRequest + * @return + */ + private String checkJob(String id, JobRequest jobRequest) { + Job job = getOne(new QueryWrapper().lambda() + .eq(Job::getCode, jobRequest.getCode()) + .ne(StrUtil.isNotBlank(id), Job::getId, id) + .last("limit 1") + ); + if(ObjUtil.isNotEmpty(job)) return "岗位编码不能重复"; + + job = getOne(new QueryWrapper().lambda() + .eq(Job::getName, jobRequest.getName()) + .ne(StrUtil.isNotBlank(id), Job::getId, id) + .last("limit 1") + ); + if(ObjUtil.isNotEmpty(job)) return "岗位名称不能重复"; + + return null; + } +} + diff --git a/src/main/java/com/ydool/system/wrapper/UserWrapper.java b/src/main/java/com/ydool/system/wrapper/UserWrapper.java index 403493b..6b20d23 100644 --- a/src/main/java/com/ydool/system/wrapper/UserWrapper.java +++ b/src/main/java/com/ydool/system/wrapper/UserWrapper.java @@ -2,15 +2,18 @@ package com.ydool.system.wrapper; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; import cn.hutool.extra.spring.SpringUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.ydool.common.base.BaseWrapper; import com.ydool.common.utils.CodecUtils; import com.ydool.system.dto.UserDto; import com.ydool.system.entity.Dept; +import com.ydool.system.entity.Job; import com.ydool.system.entity.Role; import com.ydool.system.entity.User; import com.ydool.system.service.impl.DeptServiceImpl; +import com.ydool.system.service.impl.JobServiceImpl; import com.ydool.system.service.impl.RoleServiceImpl; import org.mapstruct.AfterMapping; import org.mapstruct.Mapper; @@ -29,16 +32,25 @@ public interface UserWrapper extends BaseWrapper { default void setOtherField(User obj, @MappingTarget UserDto dto) { DeptServiceImpl deptService = SpringUtil.getBean(DeptServiceImpl.class); RoleServiceImpl roleService = SpringUtil.getBean(RoleServiceImpl.class); + JobServiceImpl jobService = SpringUtil.getBean(JobServiceImpl.class); dto.setPhone(CodecUtils.decrypt(obj.getPhone())); Dept dept = deptService.getById(obj.getDept()); if (ObjectUtil.isNotNull(dept)) dto.setDeptName(dept.getName()); - List roles = roleService.list(new QueryWrapper().lambda() - .in(Role::getId, Arrays.asList(obj.getRoles().split( - ","))) - .eq(Role::getStatus, true) - .orderByAsc(Role::getSortNo) + if (StrUtil.isNotBlank(obj.getRoles())) { + List roles = roleService.list(new QueryWrapper().lambda() + .in(Role::getId, Arrays.asList(obj.getRoles().split( + ","))) + .eq(Role::getStatus, true) + .orderByAsc(Role::getSortNo) + ); + if (CollUtil.isNotEmpty(roles)) + dto.setRolesName(roles.stream().map(Role::getName).collect(Collectors.joining(","))); + } + Job job = jobService.getOne(new QueryWrapper().lambda() + .eq(Job::getStatus, true) + .eq(Job::getId, obj.getJob()) + .last("limit 1") ); - if (CollUtil.isNotEmpty(roles)) - dto.setRolesName(roles.stream().map(Role::getName).collect(Collectors.joining(","))); + if (ObjectUtil.isNotNull(job)) dto.setJobName(job.getName()); } }