mirror of https://github.com/elunez/eladmin
remove job
parent
52c1c8b328
commit
bd9a0cf243
|
@ -1,73 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2019-2025 Zheng Jie
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package me.zhengjie.modules.system.domain;
|
|
||||||
|
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
import me.zhengjie.base.BaseEntity;
|
|
||||||
import javax.persistence.*;
|
|
||||||
import javax.validation.constraints.NotBlank;
|
|
||||||
import javax.validation.constraints.NotNull;
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Zheng Jie
|
|
||||||
* @date 2019-03-29
|
|
||||||
*/
|
|
||||||
@Entity
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
@Table(name="sys_job")
|
|
||||||
public class Job extends BaseEntity implements Serializable {
|
|
||||||
|
|
||||||
@Id
|
|
||||||
@Column(name = "job_id")
|
|
||||||
@NotNull(groups = Update.class)
|
|
||||||
@ApiModelProperty(value = "ID", hidden = true)
|
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
@NotBlank
|
|
||||||
@ApiModelProperty(value = "岗位名称")
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@ApiModelProperty(value = "岗位排序")
|
|
||||||
private Long jobSort;
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@ApiModelProperty(value = "是否启用")
|
|
||||||
private Boolean enabled;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (o == null || getClass() != o.getClass()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
Job job = (Job) o;
|
|
||||||
return Objects.equals(id, job.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hash(id);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -52,13 +52,6 @@ public class User extends BaseEntity implements Serializable {
|
||||||
inverseJoinColumns = {@JoinColumn(name = "role_id",referencedColumnName = "role_id")})
|
inverseJoinColumns = {@JoinColumn(name = "role_id",referencedColumnName = "role_id")})
|
||||||
private Set<Role> roles;
|
private Set<Role> roles;
|
||||||
|
|
||||||
@ManyToMany(fetch = FetchType.EAGER)
|
|
||||||
@ApiModelProperty(value = "用户岗位")
|
|
||||||
@JoinTable(name = "sys_users_jobs",
|
|
||||||
joinColumns = {@JoinColumn(name = "user_id",referencedColumnName = "user_id")},
|
|
||||||
inverseJoinColumns = {@JoinColumn(name = "job_id",referencedColumnName = "job_id")})
|
|
||||||
private Set<Job> jobs;
|
|
||||||
|
|
||||||
@OneToOne
|
@OneToOne
|
||||||
@JoinColumn(name = "dept_id")
|
@JoinColumn(name = "dept_id")
|
||||||
@ApiModelProperty(value = "用户部门")
|
@ApiModelProperty(value = "用户部门")
|
||||||
|
|
|
@ -1,42 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2019-2025 Zheng Jie
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package me.zhengjie.modules.system.repository;
|
|
||||||
|
|
||||||
import me.zhengjie.modules.system.domain.Job;
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
|
||||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
|
||||||
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Zheng Jie
|
|
||||||
* @date 2019-03-29
|
|
||||||
*/
|
|
||||||
public interface JobRepository extends JpaRepository<Job, Long>, JpaSpecificationExecutor<Job> {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据名称查询
|
|
||||||
* @param name 名称
|
|
||||||
* @return /
|
|
||||||
*/
|
|
||||||
Job findByName(String name);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据Id删除
|
|
||||||
* @param ids /
|
|
||||||
*/
|
|
||||||
void deleteAllByIdIn(Set<Long> ids);
|
|
||||||
}
|
|
|
@ -103,14 +103,6 @@ public interface UserRepository extends JpaRepository<User, Long>, JpaSpecificat
|
||||||
*/
|
*/
|
||||||
void deleteAllByIdIn(Set<Long> ids);
|
void deleteAllByIdIn(Set<Long> ids);
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据岗位查询
|
|
||||||
* @param ids /
|
|
||||||
* @return /
|
|
||||||
*/
|
|
||||||
@Query(value = "SELECT count(1) FROM sys_user u, sys_users_jobs j WHERE u.user_id = j.user_id AND j.job_id IN ?1", nativeQuery = true)
|
|
||||||
int countByJobs(Set<Long> ids);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据部门查询
|
* 根据部门查询
|
||||||
* @param deptIds /
|
* @param deptIds /
|
||||||
|
|
|
@ -1,96 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2019-2025 Zheng Jie
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package me.zhengjie.modules.system.rest;
|
|
||||||
|
|
||||||
import io.swagger.annotations.Api;
|
|
||||||
import io.swagger.annotations.ApiOperation;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import me.zhengjie.annotation.Log;
|
|
||||||
import me.zhengjie.exception.BadRequestException;
|
|
||||||
import me.zhengjie.modules.system.domain.Job;
|
|
||||||
import me.zhengjie.modules.system.service.JobService;
|
|
||||||
import me.zhengjie.modules.system.service.dto.JobDto;
|
|
||||||
import me.zhengjie.modules.system.service.dto.JobQueryCriteria;
|
|
||||||
import me.zhengjie.utils.PageResult;
|
|
||||||
import org.springframework.data.domain.Pageable;
|
|
||||||
import org.springframework.http.HttpStatus;
|
|
||||||
import org.springframework.http.ResponseEntity;
|
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
|
||||||
import org.springframework.validation.annotation.Validated;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Zheng Jie
|
|
||||||
* @date 2019-03-29
|
|
||||||
*/
|
|
||||||
@RestController
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
@Api(tags = "系统:岗位管理")
|
|
||||||
@RequestMapping("/api/job")
|
|
||||||
public class JobController {
|
|
||||||
|
|
||||||
private final JobService jobService;
|
|
||||||
private static final String ENTITY_NAME = "job";
|
|
||||||
|
|
||||||
@ApiOperation("导出岗位数据")
|
|
||||||
@GetMapping(value = "/download")
|
|
||||||
@PreAuthorize("@el.check('job:list')")
|
|
||||||
public void exportJob(HttpServletResponse response, JobQueryCriteria criteria) throws IOException {
|
|
||||||
jobService.download(jobService.queryAll(criteria), response);
|
|
||||||
}
|
|
||||||
|
|
||||||
@ApiOperation("查询岗位")
|
|
||||||
@GetMapping
|
|
||||||
@PreAuthorize("@el.check('job:list','user:list')")
|
|
||||||
public ResponseEntity<PageResult<JobDto>> queryJob(JobQueryCriteria criteria, Pageable pageable){
|
|
||||||
return new ResponseEntity<>(jobService.queryAll(criteria, pageable),HttpStatus.OK);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Log("新增岗位")
|
|
||||||
@ApiOperation("新增岗位")
|
|
||||||
@PostMapping
|
|
||||||
@PreAuthorize("@el.check('job:add')")
|
|
||||||
public ResponseEntity<Object> createJob(@Validated @RequestBody Job resources){
|
|
||||||
if (resources.getId() != null) {
|
|
||||||
throw new BadRequestException("A new "+ ENTITY_NAME +" cannot already have an ID");
|
|
||||||
}
|
|
||||||
jobService.create(resources);
|
|
||||||
return new ResponseEntity<>(HttpStatus.CREATED);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Log("修改岗位")
|
|
||||||
@ApiOperation("修改岗位")
|
|
||||||
@PutMapping
|
|
||||||
@PreAuthorize("@el.check('job:edit')")
|
|
||||||
public ResponseEntity<Object> updateJob(@Validated(Job.Update.class) @RequestBody Job resources){
|
|
||||||
jobService.update(resources);
|
|
||||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Log("删除岗位")
|
|
||||||
@ApiOperation("删除岗位")
|
|
||||||
@DeleteMapping
|
|
||||||
@PreAuthorize("@el.check('job:del')")
|
|
||||||
public ResponseEntity<Object> deleteJob(@RequestBody Set<Long> ids){
|
|
||||||
// 验证是否被用户关联
|
|
||||||
jobService.verification(ids);
|
|
||||||
jobService.delete(ids);
|
|
||||||
return new ResponseEntity<>(HttpStatus.OK);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,88 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2019-2025 Zheng Jie
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package me.zhengjie.modules.system.service;
|
|
||||||
|
|
||||||
import me.zhengjie.utils.PageResult;
|
|
||||||
import me.zhengjie.modules.system.domain.Job;
|
|
||||||
import me.zhengjie.modules.system.service.dto.JobDto;
|
|
||||||
import me.zhengjie.modules.system.service.dto.JobQueryCriteria;
|
|
||||||
import org.springframework.data.domain.Pageable;
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Zheng Jie
|
|
||||||
* @date 2019-03-29
|
|
||||||
*/
|
|
||||||
public interface JobService {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据ID查询
|
|
||||||
* @param id /
|
|
||||||
* @return /
|
|
||||||
*/
|
|
||||||
JobDto findById(Long id);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建
|
|
||||||
* @param resources /
|
|
||||||
* @return /
|
|
||||||
*/
|
|
||||||
void create(Job resources);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 编辑
|
|
||||||
* @param resources /
|
|
||||||
*/
|
|
||||||
void update(Job resources);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除
|
|
||||||
* @param ids /
|
|
||||||
*/
|
|
||||||
void delete(Set<Long> ids);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 分页查询
|
|
||||||
* @param criteria 条件
|
|
||||||
* @param pageable 分页参数
|
|
||||||
* @return /
|
|
||||||
*/
|
|
||||||
PageResult<JobDto> queryAll(JobQueryCriteria criteria, Pageable pageable);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询全部数据
|
|
||||||
* @param criteria /
|
|
||||||
* @return /
|
|
||||||
*/
|
|
||||||
List<JobDto> queryAll(JobQueryCriteria criteria);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 导出数据
|
|
||||||
* @param queryAll 待导出的数据
|
|
||||||
* @param response /
|
|
||||||
* @throws IOException /
|
|
||||||
*/
|
|
||||||
void download(List<JobDto> queryAll, HttpServletResponse response) throws IOException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 验证是否被用户关联
|
|
||||||
* @param ids /
|
|
||||||
*/
|
|
||||||
void verification(Set<Long> ids);
|
|
||||||
}
|
|
|
@ -1,51 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2019-2025 Zheng Jie
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package me.zhengjie.modules.system.service.dto;
|
|
||||||
|
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
import lombok.Setter;
|
|
||||||
import me.zhengjie.base.BaseDTO;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Zheng Jie
|
|
||||||
* @date 2019-03-29
|
|
||||||
*/
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
@NoArgsConstructor
|
|
||||||
public class JobDto extends BaseDTO implements Serializable {
|
|
||||||
|
|
||||||
@ApiModelProperty(value = "ID")
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
@ApiModelProperty(value = "岗位排序")
|
|
||||||
private Integer jobSort;
|
|
||||||
|
|
||||||
@ApiModelProperty(value = "名称")
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
@ApiModelProperty(value = "是否启用")
|
|
||||||
private Boolean enabled;
|
|
||||||
|
|
||||||
public JobDto(String name, Boolean enabled) {
|
|
||||||
this.name = name;
|
|
||||||
this.enabled = enabled;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,44 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2019-2025 Zheng Jie
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package me.zhengjie.modules.system.service.dto;
|
|
||||||
|
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
import me.zhengjie.annotation.Query;
|
|
||||||
import java.sql.Timestamp;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Zheng Jie
|
|
||||||
* @date 2019-6-4 14:49:34
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@NoArgsConstructor
|
|
||||||
public class JobQueryCriteria {
|
|
||||||
|
|
||||||
@ApiModelProperty(value = "岗位名称")
|
|
||||||
@Query(type = Query.Type.INNER_LIKE)
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
@Query
|
|
||||||
@ApiModelProperty(value = "岗位状态")
|
|
||||||
private Boolean enabled;
|
|
||||||
|
|
||||||
@ApiModelProperty(value = "创建时间")
|
|
||||||
@Query(type = Query.Type.BETWEEN)
|
|
||||||
private List<Timestamp> createTime;
|
|
||||||
}
|
|
|
@ -1,36 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2019-2025 Zheng Jie
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package me.zhengjie.modules.system.service.dto;
|
|
||||||
|
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Zheng Jie
|
|
||||||
* @date 2019-6-10 16:32:18
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@NoArgsConstructor
|
|
||||||
public class JobSmallDto implements Serializable {
|
|
||||||
|
|
||||||
@ApiModelProperty(value = "ID")
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
@ApiModelProperty(value = "名称")
|
|
||||||
private String name;
|
|
||||||
}
|
|
|
@ -38,9 +38,6 @@ public class UserDto extends BaseDTO implements Serializable {
|
||||||
@ApiModelProperty(value = "角色")
|
@ApiModelProperty(value = "角色")
|
||||||
private Set<RoleSmallDto> roles;
|
private Set<RoleSmallDto> roles;
|
||||||
|
|
||||||
@ApiModelProperty(value = "岗位")
|
|
||||||
private Set<JobSmallDto> jobs;
|
|
||||||
|
|
||||||
@ApiModelProperty(value = "部门")
|
@ApiModelProperty(value = "部门")
|
||||||
private DeptSmallDto dept;
|
private DeptSmallDto dept;
|
||||||
|
|
||||||
|
|
|
@ -1,136 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2019-2025 Zheng Jie
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package me.zhengjie.modules.system.service.impl;
|
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import me.zhengjie.utils.PageResult;
|
|
||||||
import me.zhengjie.exception.BadRequestException;
|
|
||||||
import me.zhengjie.exception.EntityExistException;
|
|
||||||
import me.zhengjie.modules.system.domain.Job;
|
|
||||||
import me.zhengjie.modules.system.repository.UserRepository;
|
|
||||||
import me.zhengjie.modules.system.service.dto.JobQueryCriteria;
|
|
||||||
import me.zhengjie.utils.*;
|
|
||||||
import me.zhengjie.modules.system.repository.JobRepository;
|
|
||||||
import me.zhengjie.modules.system.service.JobService;
|
|
||||||
import me.zhengjie.modules.system.service.dto.JobDto;
|
|
||||||
import me.zhengjie.modules.system.service.mapstruct.JobMapper;
|
|
||||||
import org.springframework.data.domain.Page;
|
|
||||||
import org.springframework.data.domain.Pageable;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Zheng Jie
|
|
||||||
* @date 2019-03-29
|
|
||||||
*/
|
|
||||||
@Service
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class JobServiceImpl implements JobService {
|
|
||||||
|
|
||||||
private final JobRepository jobRepository;
|
|
||||||
private final JobMapper jobMapper;
|
|
||||||
private final RedisUtils redisUtils;
|
|
||||||
private final UserRepository userRepository;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public PageResult<JobDto> queryAll(JobQueryCriteria criteria, Pageable pageable) {
|
|
||||||
Page<Job> page = jobRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
|
|
||||||
return PageUtil.toPage(page.map(jobMapper::toDto).getContent(),page.getTotalElements());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<JobDto> queryAll(JobQueryCriteria criteria) {
|
|
||||||
List<Job> list = jobRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder));
|
|
||||||
return jobMapper.toDto(list);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public JobDto findById(Long id) {
|
|
||||||
String key = CacheKey.JOB_ID + id;
|
|
||||||
Job job = redisUtils.get(key, Job.class);
|
|
||||||
if(job == null){
|
|
||||||
job = jobRepository.findById(id).orElseGet(Job::new);
|
|
||||||
ValidationUtil.isNull(job.getId(),"Job","id",id);
|
|
||||||
redisUtils.set(key, job, 1, TimeUnit.DAYS);
|
|
||||||
}
|
|
||||||
return jobMapper.toDto(job);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
|
||||||
public void create(Job resources) {
|
|
||||||
Job job = jobRepository.findByName(resources.getName());
|
|
||||||
if(job != null){
|
|
||||||
throw new EntityExistException(Job.class,"name",resources.getName());
|
|
||||||
}
|
|
||||||
jobRepository.save(resources);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
|
||||||
public void update(Job resources) {
|
|
||||||
Job job = jobRepository.findById(resources.getId()).orElseGet(Job::new);
|
|
||||||
Job old = jobRepository.findByName(resources.getName());
|
|
||||||
if(old != null && !old.getId().equals(resources.getId())){
|
|
||||||
throw new EntityExistException(Job.class,"name",resources.getName());
|
|
||||||
}
|
|
||||||
ValidationUtil.isNull( job.getId(),"Job","id",resources.getId());
|
|
||||||
resources.setId(job.getId());
|
|
||||||
jobRepository.save(resources);
|
|
||||||
// 删除缓存
|
|
||||||
delCaches(resources.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
|
||||||
public void delete(Set<Long> ids) {
|
|
||||||
jobRepository.deleteAllByIdIn(ids);
|
|
||||||
// 删除缓存
|
|
||||||
redisUtils.delByKeys(CacheKey.JOB_ID, ids);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void download(List<JobDto> jobDtos, HttpServletResponse response) throws IOException {
|
|
||||||
List<Map<String, Object>> list = new ArrayList<>();
|
|
||||||
for (JobDto jobDTO : jobDtos) {
|
|
||||||
Map<String,Object> map = new LinkedHashMap<>();
|
|
||||||
map.put("岗位名称", jobDTO.getName());
|
|
||||||
map.put("岗位状态", jobDTO.getEnabled() ? "启用" : "停用");
|
|
||||||
map.put("创建日期", jobDTO.getCreateTime());
|
|
||||||
list.add(map);
|
|
||||||
}
|
|
||||||
FileUtil.downloadExcel(list, response);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void verification(Set<Long> ids) {
|
|
||||||
if(userRepository.countByJobs(ids) > 0){
|
|
||||||
throw new BadRequestException("所选的岗位中存在用户关联,请解除关联再试!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除缓存
|
|
||||||
* @param id /
|
|
||||||
*/
|
|
||||||
public void delCaches(Long id){
|
|
||||||
redisUtils.del(CacheKey.JOB_ID + id);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -134,7 +134,6 @@ public class UserServiceImpl implements UserService {
|
||||||
user.setEnabled(resources.getEnabled());
|
user.setEnabled(resources.getEnabled());
|
||||||
user.setRoles(resources.getRoles());
|
user.setRoles(resources.getRoles());
|
||||||
user.setDept(resources.getDept());
|
user.setDept(resources.getDept());
|
||||||
user.setJobs(resources.getJobs());
|
|
||||||
user.setPhone(resources.getPhone());
|
user.setPhone(resources.getPhone());
|
||||||
user.setNickName(resources.getNickName());
|
user.setNickName(resources.getNickName());
|
||||||
user.setGender(resources.getGender());
|
user.setGender(resources.getGender());
|
||||||
|
@ -255,7 +254,6 @@ public class UserServiceImpl implements UserService {
|
||||||
map.put("用户名", userDTO.getUsername());
|
map.put("用户名", userDTO.getUsername());
|
||||||
map.put("角色", roles);
|
map.put("角色", roles);
|
||||||
map.put("部门", userDTO.getDept().getName());
|
map.put("部门", userDTO.getDept().getName());
|
||||||
map.put("岗位", userDTO.getJobs().stream().map(JobSmallDto::getName).collect(Collectors.toList()));
|
|
||||||
map.put("邮箱", userDTO.getEmail());
|
map.put("邮箱", userDTO.getEmail());
|
||||||
map.put("状态", userDTO.getEnabled() ? "启用" : "禁用");
|
map.put("状态", userDTO.getEnabled() ? "启用" : "禁用");
|
||||||
map.put("手机号码", userDTO.getPhone());
|
map.put("手机号码", userDTO.getPhone());
|
||||||
|
|
|
@ -1,30 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2019-2025 Zheng Jie
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package me.zhengjie.modules.system.service.mapstruct;
|
|
||||||
|
|
||||||
import me.zhengjie.base.BaseMapper;
|
|
||||||
import me.zhengjie.modules.system.domain.Job;
|
|
||||||
import me.zhengjie.modules.system.service.dto.JobDto;
|
|
||||||
import org.mapstruct.Mapper;
|
|
||||||
import org.mapstruct.ReportingPolicy;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Zheng Jie
|
|
||||||
* @date 2019-03-29
|
|
||||||
*/
|
|
||||||
@Mapper(componentModel = "spring",uses = {DeptMapper.class},unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
|
||||||
public interface JobMapper extends BaseMapper<JobDto, Job> {
|
|
||||||
}
|
|
|
@ -1,31 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2019-2025 Zheng Jie
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package me.zhengjie.modules.system.service.mapstruct;
|
|
||||||
|
|
||||||
import me.zhengjie.base.BaseMapper;
|
|
||||||
import me.zhengjie.modules.system.domain.Job;
|
|
||||||
import me.zhengjie.modules.system.service.dto.JobSmallDto;
|
|
||||||
import org.mapstruct.Mapper;
|
|
||||||
import org.mapstruct.ReportingPolicy;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Zheng Jie
|
|
||||||
* @date 2019-03-29
|
|
||||||
*/
|
|
||||||
@Mapper(componentModel = "spring",unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
|
||||||
public interface JobSmallMapper extends BaseMapper<JobSmallDto, Job> {
|
|
||||||
|
|
||||||
}
|
|
|
@ -25,6 +25,6 @@ import org.mapstruct.ReportingPolicy;
|
||||||
* @author Zheng Jie
|
* @author Zheng Jie
|
||||||
* @date 2018-11-23
|
* @date 2018-11-23
|
||||||
*/
|
*/
|
||||||
@Mapper(componentModel = "spring",uses = {RoleMapper.class, DeptMapper.class, JobMapper.class},unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
@Mapper(componentModel = "spring",uses = {RoleMapper.class, DeptMapper.class},unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
||||||
public interface UserMapper extends BaseMapper<UserDto, User> {
|
public interface UserMapper extends BaseMapper<UserDto, User> {
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
create table event_organizer
|
||||||
|
(
|
||||||
|
id bigint auto_increment primary key,
|
||||||
|
user_id bigint not null references sys_user (user_id),
|
||||||
|
club_id bigint null references club (id)
|
||||||
|
);
|
||||||
|
|
||||||
|
drop table sys_users_jobs;
|
||||||
|
|
||||||
|
drop table sys_job;
|
Loading…
Reference in New Issue