部门和岗位增删改查完成
This commit is contained in:
parent
5070e42c09
commit
17917a834b
|
@ -31,4 +31,15 @@ public class Constants {
|
|||
* 1:代表删除
|
||||
*/
|
||||
public static final String DEL_FLAG_1 = "1";
|
||||
|
||||
/**
|
||||
* 0:代表启用
|
||||
*/
|
||||
public static final Integer STATUS_0 = 0;
|
||||
|
||||
/**
|
||||
* 1:代表停用
|
||||
*/
|
||||
public static final Integer STATUS_1 = 1;
|
||||
|
||||
}
|
||||
|
|
|
@ -21,4 +21,10 @@ public class Message implements Serializable {
|
|||
public static final String PART_ID_IS_NOT_EXIST = "部件id不存在";
|
||||
public static final String IMAGE_SOURCE_ID_NOT_EXIST_OR_ILLEGAL = "部件id不存在";
|
||||
public static final String USER_ID_NOT_EXIST = "用户id不存在";
|
||||
public static final String ACCOUNT_EXIST = "用户账号已经存在,请重新输入";
|
||||
public static final String MOBILE_EXIST = "手机号码已经存在,请重新输入";
|
||||
public static final String EMAIL_EXIST = "邮箱已经存在,请重新输入";
|
||||
public static final String DEPT_PARENT_NOT_EXISTS = "父级部门不存在";
|
||||
public static final String DEPT_ID_NOT_EXISTS = "部门id不存在";
|
||||
public static final String POST_ID_NOT_EXISTS = "岗位id不存在";
|
||||
}
|
||||
|
|
|
@ -42,4 +42,16 @@ public interface Converts {
|
|||
UserResp toUserResp(UserEntity entity);
|
||||
|
||||
UserEntity toUserEntity(UserReq req);
|
||||
|
||||
DeptEntity toDeptEntity(DeptReq req);
|
||||
|
||||
DeptResp toDeptResp(DeptEntity entity);
|
||||
|
||||
PostEntity toPostEntity(PostReq req);
|
||||
|
||||
List<PostResp> toPostResp(List<PostEntity> list);
|
||||
|
||||
PostResp toPostResp(PostEntity entity);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,64 @@
|
|||
package com.dite.znpt.domain.entity;
|
||||
|
||||
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.dite.znpt.domain.AuditableEntity;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author Bear.G
|
||||
* @date 2025/5/20/周二 9:17
|
||||
* @description
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("dept")
|
||||
@ApiModel(value="DeptEntity对象", description="表")
|
||||
public class DeptEntity extends AuditableEntity implements Serializable {
|
||||
@Serial
|
||||
private static final long serialVersionUID = -6471015140726790051L;
|
||||
|
||||
@ApiModelProperty("部门id")
|
||||
@TableId(value = "dept_id", type = IdType.ASSIGN_UUID)
|
||||
private String deptId;
|
||||
|
||||
@ApiModelProperty("父级部门id")
|
||||
@TableField("parent_id")
|
||||
private String parentId;
|
||||
|
||||
@ApiModelProperty("祖籍列表")
|
||||
@TableField("ancestors")
|
||||
private String ancestors;
|
||||
|
||||
@ApiModelProperty("部门全路径名称")
|
||||
@TableField("dept_full_name")
|
||||
private String deptFullName;
|
||||
|
||||
@ApiModelProperty("部门名称")
|
||||
@TableField("dept_name")
|
||||
private String deptName;
|
||||
|
||||
@ApiModelProperty("显示顺序")
|
||||
@TableField("order_num")
|
||||
private Integer orderNum;
|
||||
|
||||
@ApiModelProperty("部门负责人")
|
||||
@TableField("leader_id")
|
||||
private String leaderId;
|
||||
|
||||
@ApiModelProperty("状态(0正常 1停用)")
|
||||
@TableField("status")
|
||||
private Integer status;
|
||||
|
||||
@ApiModelProperty("删除标志(0代表存在 1代表删除)")
|
||||
@TableField("del_flag")
|
||||
private String delFlag;
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
package com.dite.znpt.domain.entity;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
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.dite.znpt.domain.AuditableEntity;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author Bear.G
|
||||
* @date 2025/5/20/周二 9:17
|
||||
* @description
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("post")
|
||||
@ApiModel(value="PostEntity对象", description="表")
|
||||
public class PostEntity extends AuditableEntity implements Serializable {
|
||||
@Serial
|
||||
private static final long serialVersionUID = -5163882523494504223L;
|
||||
|
||||
@ApiModelProperty("岗位id")
|
||||
@TableId(value = "post_id", type = IdType.ASSIGN_UUID)
|
||||
private String postId;
|
||||
|
||||
@ApiModelProperty("岗位名称")
|
||||
@TableField("post_name")
|
||||
private String postName;
|
||||
|
||||
@ApiModelProperty("显示顺序")
|
||||
@TableField("post_sort")
|
||||
private Integer postSort;
|
||||
|
||||
@ApiModelProperty("状态(0正常 1停用)")
|
||||
@TableField("status")
|
||||
private Integer status;
|
||||
|
||||
@ApiModelProperty("备注")
|
||||
@TableField("remark")
|
||||
private String remark;
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
package com.dite.znpt.domain.vo;
|
||||
|
||||
import com.dite.znpt.util.ValidationGroup;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.Size;
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author Bear.G
|
||||
* @date 2025/5/20/周二 9:42
|
||||
* @description
|
||||
*/
|
||||
@Data
|
||||
@ApiModel("部门信息请求实体")
|
||||
public class DeptReq implements Serializable {
|
||||
@Serial
|
||||
private static final long serialVersionUID = -8058508810161877848L;
|
||||
|
||||
@ApiModelProperty("父级部门id")
|
||||
private String parentId;
|
||||
|
||||
@NotBlank(groups = {ValidationGroup.Insert.class, ValidationGroup.Update.class}, message = "部门名称不能为空")
|
||||
@Size(max = 30, groups = {ValidationGroup.Insert.class, ValidationGroup.Update.class}, message = "部门名称长度不能超过30")
|
||||
@ApiModelProperty("部门名称")
|
||||
private String deptName;
|
||||
|
||||
@ApiModelProperty("显示顺序")
|
||||
private Integer orderNum;
|
||||
|
||||
@ApiModelProperty("负责人id")
|
||||
private String leaderId;
|
||||
|
||||
@ApiModelProperty("状态")
|
||||
private Integer status;
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package com.dite.znpt.domain.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author Bear.G
|
||||
* @date 2025/5/20/周二 9:40
|
||||
* @description
|
||||
*/
|
||||
@Data
|
||||
@ApiModel("部门信息响应实体")
|
||||
public class DeptResp implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 6372397386719274915L;
|
||||
|
||||
@ApiModelProperty("部门id")
|
||||
private String deptId;
|
||||
|
||||
@ApiModelProperty("部门名称")
|
||||
private String deptName;
|
||||
|
||||
@ApiModelProperty("父级部门id")
|
||||
private String parentId;
|
||||
|
||||
@ApiModelProperty("部门排序")
|
||||
private Integer orderNum;
|
||||
|
||||
@ApiModelProperty("部门负责人id")
|
||||
private String leaderId;
|
||||
|
||||
@ApiModelProperty("部门状态")
|
||||
private String status;
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package com.dite.znpt.domain.vo;
|
||||
|
||||
import com.dite.znpt.util.ValidationGroup;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.Size;
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author Bear.G
|
||||
* @date 2025/5/20/周二 9:43
|
||||
* @description
|
||||
*/
|
||||
@Data
|
||||
@ApiModel("岗位信息请求实体")
|
||||
public class PostReq implements Serializable {
|
||||
@Serial
|
||||
private static final long serialVersionUID = -149328762675637911L;
|
||||
|
||||
@NotBlank(groups = {ValidationGroup.Insert.class, ValidationGroup.Update.class}, message = "岗位名称不能为空")
|
||||
@Size(max = 30, groups = {ValidationGroup.Insert.class, ValidationGroup.Update.class}, message = "岗位名称长度不能超过30个字符")
|
||||
@ApiModelProperty("岗位名称")
|
||||
private String postName;
|
||||
|
||||
@ApiModelProperty("显示顺序")
|
||||
private Integer postSort;
|
||||
|
||||
@ApiModelProperty("状态(0正常 1停用)")
|
||||
private Integer status;
|
||||
|
||||
@ApiModelProperty("备注")
|
||||
private String remark;
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package com.dite.znpt.domain.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.Size;
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author Bear.G
|
||||
* @date 2025/5/20/周二 9:42
|
||||
* @description
|
||||
*/
|
||||
@Data
|
||||
@ApiModel("岗位信息响应实体")
|
||||
public class PostResp implements Serializable {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 8836143545716686582L;
|
||||
|
||||
@ApiModelProperty("岗位id")
|
||||
private String postId;
|
||||
|
||||
@ApiModelProperty("岗位名称")
|
||||
private String postName;
|
||||
|
||||
@ApiModelProperty("显示顺序")
|
||||
private Integer postSort;
|
||||
|
||||
@ApiModelProperty("状态")
|
||||
private String status;
|
||||
|
||||
@Size(max = 200, message = "备注长度不能超过200个字符")
|
||||
@ApiModelProperty("备注")
|
||||
private String remark;
|
||||
|
||||
}
|
|
@ -9,37 +9,6 @@ import lombok.Getter;
|
|||
* @description: 枚举类
|
||||
*/
|
||||
public class Enums {
|
||||
/**
|
||||
* @date 2021/9/15 3:24 下午
|
||||
* @description: N:正常,D:删除
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum YN {
|
||||
/**
|
||||
* @date 2021/9/15 3:24 下午
|
||||
* @description: 正常
|
||||
*/
|
||||
Yes(1, "是"),
|
||||
/**
|
||||
* @date 2021/9/15 3:24 下午
|
||||
* @description: 启用
|
||||
*/
|
||||
No(0, "否");
|
||||
|
||||
final int value;
|
||||
final String name;
|
||||
}
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum EUserStatus {
|
||||
ENABLE(1, "启用"),
|
||||
DISABLE(0, "禁用");
|
||||
|
||||
final int value;
|
||||
final String name;
|
||||
}
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
package com.dite.znpt.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.dite.znpt.domain.entity.DeptEntity;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Bear.G
|
||||
* @date 2025/5/20/周二 10:16
|
||||
* @description
|
||||
*/
|
||||
public interface DeptMapper extends BaseMapper<DeptEntity> {
|
||||
/**
|
||||
* @Author Bear.G
|
||||
* @Date 2025/5/20/周二 15:49
|
||||
* @description 向上递归查询部门树
|
||||
* @param deptName
|
||||
* @return
|
||||
**/
|
||||
List<DeptEntity> upwardRecursionSelect(@Param("deptName") String deptName);
|
||||
|
||||
/**
|
||||
* @Author Bear.G
|
||||
* @Date 2025/5/20/周二 15:49
|
||||
* @description 向下递归查询部门树
|
||||
* @param deptId
|
||||
* @return
|
||||
**/
|
||||
List<DeptEntity> downwardRecursionSelect(@Param("deptId") String deptId);
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package com.dite.znpt.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.dite.znpt.domain.entity.PostEntity;
|
||||
|
||||
/**
|
||||
* @author Bear.G
|
||||
* @date 2025/5/20/周二 10:16
|
||||
* @description
|
||||
*/
|
||||
public interface PostMapper extends BaseMapper<PostEntity> {
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package com.dite.znpt.service;
|
||||
|
||||
import cn.hutool.core.lang.tree.Tree;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.dite.znpt.domain.entity.DeptEntity;
|
||||
import com.dite.znpt.domain.vo.DeptReq;
|
||||
import com.dite.znpt.domain.vo.DeptResp;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Bear.G
|
||||
* @date 2025/5/20/周二 10:14
|
||||
* @description
|
||||
*/
|
||||
public interface DeptService extends IService<DeptEntity> {
|
||||
|
||||
List<Tree<String>> tree(String deptName);
|
||||
|
||||
DeptResp detail(String deptId);
|
||||
|
||||
void save(DeptReq req);
|
||||
|
||||
void update(String deptId, DeptReq req);
|
||||
|
||||
void deleteById(String deptId);
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package com.dite.znpt.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.dite.znpt.domain.entity.PostEntity;
|
||||
import com.dite.znpt.domain.vo.PostReq;
|
||||
import com.dite.znpt.domain.vo.PostResp;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Bear.G
|
||||
* @date 2025/5/20/周二 10:20
|
||||
* @description
|
||||
*/
|
||||
public interface PostService extends IService<PostEntity> {
|
||||
|
||||
List<PostResp> page(String postName);
|
||||
|
||||
List<PostResp> list(String postName);
|
||||
|
||||
PostResp detail(String postId);
|
||||
|
||||
void save(PostReq req);
|
||||
|
||||
void update(String postId, PostReq req);
|
||||
|
||||
void deleteById(String postId);
|
||||
}
|
|
@ -0,0 +1,116 @@
|
|||
package com.dite.znpt.service.impl;
|
||||
|
||||
import cn.hutool.core.lang.tree.Tree;
|
||||
import cn.hutool.core.lang.tree.TreeNodeConfig;
|
||||
import cn.hutool.core.lang.tree.TreeUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.dite.znpt.constant.Constants;
|
||||
import com.dite.znpt.constant.Message;
|
||||
import com.dite.znpt.converts.Converts;
|
||||
import com.dite.znpt.domain.entity.DeptEntity;
|
||||
import com.dite.znpt.domain.entity.UserEntity;
|
||||
import com.dite.znpt.domain.vo.DeptReq;
|
||||
import com.dite.znpt.domain.vo.DeptResp;
|
||||
import com.dite.znpt.exception.ServiceException;
|
||||
import com.dite.znpt.mapper.DeptMapper;
|
||||
import com.dite.znpt.service.DeptService;
|
||||
import com.dite.znpt.service.UserService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Bear.G
|
||||
* @date 2025/5/20/周二 10:14
|
||||
* @description
|
||||
*/
|
||||
@Service
|
||||
public class DeptServiceImpl extends ServiceImpl<DeptMapper, DeptEntity> implements DeptService {
|
||||
|
||||
@Resource
|
||||
private UserService userService;
|
||||
|
||||
@Override
|
||||
public List<Tree<String>> tree(String deptName) {
|
||||
List<DeptEntity> deptList = StrUtil.isBlank(deptName) ? this.baseMapper.downwardRecursionSelect(null) : this.baseMapper.upwardRecursionSelect(deptName);
|
||||
//配置
|
||||
TreeNodeConfig treeNodeConfig = new TreeNodeConfig();
|
||||
treeNodeConfig.setIdKey("deptId");
|
||||
treeNodeConfig.setNameKey("deptName");
|
||||
treeNodeConfig.setParentIdKey("parentId");
|
||||
treeNodeConfig.setWeightKey("orderNum");
|
||||
//转换器
|
||||
return TreeUtil.build(deptList, "0", treeNodeConfig,
|
||||
(treeNode, tree) -> {
|
||||
tree.setId(treeNode.getDeptId());
|
||||
tree.setParentId(treeNode.getParentId());
|
||||
tree.setName(treeNode.getDeptName());
|
||||
tree.putExtra("status",treeNode.getStatus());
|
||||
tree.putExtra("orderNum",treeNode.getOrderNum());
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeptResp detail(String deptId) {
|
||||
DeptEntity entity = this.getById(deptId);
|
||||
if (null == entity || !entity.getDelFlag().equals(Constants.DEL_FLAG_0)){
|
||||
throw new ServiceException(Message.DEPT_ID_NOT_EXISTS);
|
||||
}
|
||||
return Converts.INSTANCE.toDeptResp(entity);
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public void save(DeptReq req) {
|
||||
this.save(dealDept(req));
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public void update(String deptId, DeptReq req) {
|
||||
DeptEntity originalEntity = this.getById(deptId);
|
||||
if (null == originalEntity || !originalEntity.getDelFlag().equals(Constants.DEL_FLAG_0)){
|
||||
throw new ServiceException(Message.DEPT_ID_NOT_EXISTS);
|
||||
}
|
||||
DeptEntity entity = dealDept(req);
|
||||
entity.setDeptId(deptId);
|
||||
this.updateById(entity);
|
||||
}
|
||||
|
||||
private DeptEntity dealDept(DeptReq req){
|
||||
DeptEntity entity = Converts.INSTANCE.toDeptEntity(req);
|
||||
if(StrUtil.isNotBlank(req.getLeaderId())){
|
||||
UserEntity user = userService.getById(req.getLeaderId());
|
||||
if(null == user || !user.getDelFlag().equals(Constants.DEL_FLAG_0)){
|
||||
throw new ServiceException(Message.USER_ID_NOT_EXIST);
|
||||
}
|
||||
}
|
||||
if(StrUtil.isNotBlank(req.getParentId())){
|
||||
DeptEntity parent = this.getById(req.getParentId());
|
||||
if(null == parent || !parent.getDelFlag().equals(Constants.DEL_FLAG_0)){
|
||||
throw new ServiceException(Message.DEPT_PARENT_NOT_EXISTS);
|
||||
}
|
||||
entity.setAncestors(parent.getAncestors() + StrUtil.COMMA + parent.getDeptId());
|
||||
entity.setDeptFullName(parent.getDeptFullName() + StrUtil.SLASH + entity.getDeptName());
|
||||
}else{
|
||||
entity.setParentId("0");
|
||||
entity.setAncestors("0");
|
||||
entity.setDeptFullName(req.getDeptName());
|
||||
}
|
||||
return entity;
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public void deleteById(String deptId) {
|
||||
DeptEntity entity = this.getById(deptId);
|
||||
if (null == entity || !entity.getDelFlag().equals(Constants.DEL_FLAG_0)){
|
||||
throw new ServiceException(Message.DEPT_ID_NOT_EXISTS);
|
||||
}
|
||||
entity.setDelFlag(Constants.DEL_FLAG_1);
|
||||
this.updateById(entity);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
package com.dite.znpt.service.impl;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.dite.znpt.constant.Message;
|
||||
import com.dite.znpt.converts.Converts;
|
||||
import com.dite.znpt.domain.entity.PostEntity;
|
||||
import com.dite.znpt.domain.vo.PostReq;
|
||||
import com.dite.znpt.domain.vo.PostResp;
|
||||
import com.dite.znpt.exception.ServiceException;
|
||||
import com.dite.znpt.mapper.PostMapper;
|
||||
import com.dite.znpt.service.PostService;
|
||||
import com.dite.znpt.util.PageUtil;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Bear.G
|
||||
* @date 2025/5/20/周二 10:20
|
||||
* @description
|
||||
*/
|
||||
@Service
|
||||
public class PostServiceImpl extends ServiceImpl<PostMapper, PostEntity> implements PostService {
|
||||
|
||||
@Override
|
||||
public List<PostResp> page(String postName) {
|
||||
PageUtil.startPage();
|
||||
return this.list(postName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PostResp> list(String postName) {
|
||||
return Converts.INSTANCE.toPostResp(this.list(Wrappers.lambdaQuery(PostEntity.class).like(StrUtil.isNotBlank(postName), PostEntity::getPostName, postName)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public PostResp detail(String postId) {
|
||||
return Converts.INSTANCE.toPostResp(this.getById(postId));
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public void save(PostReq req) {
|
||||
PostEntity entity = Converts.INSTANCE.toPostEntity(req);
|
||||
this.save(entity);
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public void update(String postId, PostReq req) {
|
||||
if(null == this.getById(postId)){
|
||||
throw new ServiceException(Message.POST_ID_NOT_EXISTS);
|
||||
}
|
||||
PostEntity entity = Converts.INSTANCE.toPostEntity(req);
|
||||
entity.setPostId(postId);
|
||||
this.updateById(entity);
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public void deleteById(String postId) {
|
||||
if(null == this.getById(postId)){
|
||||
throw new ServiceException(Message.POST_ID_NOT_EXISTS);
|
||||
}
|
||||
this.removeById(postId);
|
||||
}
|
||||
}
|
|
@ -4,6 +4,9 @@ import cn.dev33.satoken.secure.SaBase64Util;
|
|||
import cn.dev33.satoken.secure.SaSecureUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.dite.znpt.constant.Constants;
|
||||
import com.dite.znpt.constant.Message;
|
||||
|
@ -97,6 +100,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserEntity> impleme
|
|||
@Override
|
||||
public String save(UserReq req) {
|
||||
UserEntity entity = Converts.INSTANCE.toUserEntity(req);
|
||||
validate(req, null);
|
||||
String salt = RandomUtil.randomString(req.getAccount(), 4);
|
||||
entity.setSalt(salt);
|
||||
String password = enableDefaultPassword ? defaultPassword : PasswordUtil.generatePassword();
|
||||
|
@ -116,15 +120,37 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserEntity> impleme
|
|||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public void update(String userId, UserReq req) {
|
||||
if(null == this.getById(userId)){
|
||||
UserEntity originalEntity = this.getById(userId);
|
||||
if(null == originalEntity || originalEntity.getDelFlag().equals(Constants.DEL_FLAG_1)){
|
||||
throw new ServiceException(Message.USER_ID_NOT_EXIST);
|
||||
}
|
||||
UserEntity entity = Converts.INSTANCE.toUserEntity(req);
|
||||
entity.setUserId(userId);
|
||||
entity.setAccount(null);
|
||||
validate(req, originalEntity);
|
||||
this.updateById(entity);
|
||||
}
|
||||
|
||||
|
||||
private void validate(UserReq req, UserEntity originalEntity){
|
||||
LambdaQueryWrapper<UserEntity> accountWrapper = Wrappers.lambdaQuery(UserEntity.class).eq(UserEntity::getAccount, req.getAccount()).eq(UserEntity::getDelFlag, Constants.DEL_FLAG_0);
|
||||
if(this.getOne(accountWrapper) != null && originalEntity == null){
|
||||
throw new ServiceException(Message.ACCOUNT_EXIST);
|
||||
}
|
||||
if(originalEntity == null || !originalEntity.getMobile().equals(req.getMobile())){
|
||||
LambdaQueryWrapper<UserEntity> mobileWrapper = Wrappers.lambdaQuery(UserEntity.class).eq(StrUtil.isNotBlank(req.getMobile()), UserEntity::getMobile, req.getMobile()).eq(UserEntity::getDelFlag, Constants.DEL_FLAG_0);
|
||||
if(this.getOne(mobileWrapper) != null){
|
||||
throw new ServiceException(Message.MOBILE_EXIST);
|
||||
}
|
||||
}
|
||||
if(originalEntity == null || !originalEntity.getEmail().equals(req.getEmail())){
|
||||
LambdaQueryWrapper<UserEntity> emailWrapper = Wrappers.lambdaQuery(UserEntity.class).eq(StrUtil.isNotBlank(req.getEmail()), UserEntity::getEmail, req.getMobile()).eq(UserEntity::getDelFlag, Constants.DEL_FLAG_0);
|
||||
if(this.getOne(emailWrapper) != null){
|
||||
throw new ServiceException(Message.EMAIL_EXIST);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 功能描述:删除用户信息
|
||||
*
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.dite.znpt.mapper.DeptMapper">
|
||||
|
||||
<select id="upwardRecursionSelect" resultType="com.dite.znpt.domain.entity.DeptEntity">
|
||||
WITH RECURSIVE DeptPath AS (
|
||||
SELECT * FROM dept
|
||||
WHERE del_flag = '0'
|
||||
<choose>
|
||||
<when test="deptName != null and deptName != ''">
|
||||
AND dept_name LIKE concat('%',#{deptName}, '%') -- 起始部门
|
||||
</when>
|
||||
<otherwise>
|
||||
AND parent_id = '0' -- 起始部门
|
||||
</otherwise>
|
||||
</choose>
|
||||
UNION ALL
|
||||
SELECT d.* FROM dept d INNER JOIN DeptPath dp ON d.dept_id = dp.parent_id WHERE d.del_flag = '0'
|
||||
)
|
||||
SELECT DISTINCT * FROM DeptPath;
|
||||
</select>
|
||||
|
||||
<select id="downwardRecursionSelect" resultType="com.dite.znpt.domain.entity.DeptEntity">
|
||||
WITH RECURSIVE SubDepts AS (
|
||||
SELECT * FROM dept WHERE del_flag = '0'
|
||||
<choose>
|
||||
<when test="deptId != null and deptId != ''">
|
||||
AND dept_id = #{deptId} -- 起始部门ID
|
||||
</when>
|
||||
<otherwise>
|
||||
AND parent_id = '0' -- 起始部门
|
||||
</otherwise>
|
||||
</choose>
|
||||
UNION ALL
|
||||
SELECT d.* FROM dept d INNER JOIN SubDepts sd ON d.parent_id = sd.dept_id WHERE d.del_flag = '0'
|
||||
)
|
||||
SELECT * FROM SubDepts;
|
||||
</select>
|
||||
|
||||
|
||||
</mapper>
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.dite.znpt.mapper.PostMapper">
|
||||
|
||||
</mapper>
|
|
@ -0,0 +1,62 @@
|
|||
package com.dite.znpt.web.controller;
|
||||
|
||||
import com.dite.znpt.domain.PageResult;
|
||||
import com.dite.znpt.domain.Result;
|
||||
import com.dite.znpt.domain.vo.DeptReq;
|
||||
import com.dite.znpt.domain.vo.DeptResp;
|
||||
import com.dite.znpt.service.DeptService;
|
||||
import com.dite.znpt.util.ValidationGroup;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Bear.G
|
||||
* @date 2025/5/20/周二 10:05
|
||||
* @description
|
||||
*/
|
||||
@Api(tags = "部门信息")
|
||||
@RestController
|
||||
@RequestMapping("/dept")
|
||||
public class DeptController {
|
||||
|
||||
@Resource
|
||||
private DeptService deptService;
|
||||
|
||||
@ApiOperation(value = "查询部门树", httpMethod = "GET")
|
||||
@GetMapping("/tree")
|
||||
public Result tree (@RequestParam(name = "deptName", required = false) String deptName) {
|
||||
return Result.ok(deptService.tree(deptName));
|
||||
}
|
||||
|
||||
@ApiOperation(value = "查询部门信息详情", httpMethod = "GET")
|
||||
@GetMapping("/detail/{deptId}")
|
||||
public Result<DeptResp> detail(@PathVariable String deptId) {
|
||||
return Result.ok(deptService.detail(deptId));
|
||||
}
|
||||
|
||||
@ApiOperation(value = "新增部门信息", httpMethod = "Post")
|
||||
@PostMapping
|
||||
public Result add(@Validated(ValidationGroup.Insert.class) @RequestBody DeptReq req) {
|
||||
deptService.save(req);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@ApiOperation(value = "修改部门信息", httpMethod = "PUT")
|
||||
@PutMapping("/{deptId}")
|
||||
public Result edit(@PathVariable String deptId, @Validated(ValidationGroup.Update.class) @RequestBody DeptReq req) {
|
||||
deptService.update(deptId, req);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@ApiOperation(value = "删除部门信息", httpMethod = "DELETE")
|
||||
@DeleteMapping("/{deptId}")
|
||||
public Result remove(@PathVariable String deptId) {
|
||||
deptService.deleteById(deptId);
|
||||
return Result.ok();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
package com.dite.znpt.web.controller;
|
||||
|
||||
import com.dite.znpt.domain.PageResult;
|
||||
import com.dite.znpt.domain.Result;
|
||||
import com.dite.znpt.domain.vo.PostReq;
|
||||
import com.dite.znpt.domain.vo.PostResp;
|
||||
import com.dite.znpt.service.PostService;
|
||||
import com.dite.znpt.util.ValidationGroup;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Bear.G
|
||||
* @date 2025/5/20/周二 10:05
|
||||
* @description
|
||||
*/
|
||||
@Api(tags = "岗位信息")
|
||||
@RestController
|
||||
@RequestMapping("/post")
|
||||
public class PostController {
|
||||
@Resource
|
||||
private PostService postService;
|
||||
|
||||
@ApiOperation(value = "分页查询岗位信息列表", httpMethod = "GET")
|
||||
@GetMapping("/page")
|
||||
public PageResult<PostResp> page(@RequestParam(value = "postName", required = false) String postName){
|
||||
return PageResult.ok(postService.page(postName));
|
||||
}
|
||||
|
||||
@ApiOperation(value = "查询岗位信息列表", httpMethod = "GET")
|
||||
@GetMapping("/list")
|
||||
private Result<List<PostResp>> list(@RequestParam(value = "postName", required = false) String postName){
|
||||
return Result.ok(postService.list(postName));
|
||||
}
|
||||
|
||||
@ApiOperation(value = "查询岗位信息详情", httpMethod = "GET")
|
||||
@GetMapping("/detail/{postId}")
|
||||
public Result<PostResp> detail(@PathVariable String postId){
|
||||
return Result.ok(postService.detail(postId));
|
||||
}
|
||||
|
||||
@ApiOperation(value = "新增岗位信息", httpMethod = "POST")
|
||||
@PostMapping
|
||||
public Result add(@Validated(ValidationGroup.Insert.class) @RequestBody PostReq req){
|
||||
postService.save(req);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@ApiOperation(value = "修改岗位信息", httpMethod = "PUT")
|
||||
@PutMapping("/{postId}")
|
||||
public Result edit(@PathVariable String postId, @Validated(ValidationGroup.Update.class) @RequestBody PostReq req){
|
||||
postService.update(postId, req);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@ApiOperation(value = "删除岗位信息", httpMethod = "DELETE")
|
||||
@DeleteMapping("/{postId}")
|
||||
public Result remove(@PathVariable String postId){
|
||||
postService.deleteById(postId);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
}
|
|
@ -84,7 +84,7 @@ spring:
|
|||
|
||||
sip-config:
|
||||
name: 信令服务
|
||||
ip: 192.168.0.112
|
||||
ip: 127.0.0.1
|
||||
port: 1074
|
||||
charset: gb2312
|
||||
domain: 3402000000
|
||||
|
@ -100,7 +100,7 @@ zlm-config:
|
|||
# 公网ip
|
||||
publicHost:
|
||||
# 接口ip
|
||||
apiHost: 192.168.0.112
|
||||
apiHost: 127.0.0.1
|
||||
# 接口端口
|
||||
apiPort: 8080
|
||||
# 密钥
|
||||
|
@ -108,7 +108,7 @@ zlm-config:
|
|||
# 流id前缀
|
||||
streamPrefix:
|
||||
# rtp ip
|
||||
rtpHost: 192.168.0.112
|
||||
rtpHost: 127.0.0.1
|
||||
# rtp 端口
|
||||
rtpPort: 8080
|
||||
# 动态端口起始值
|
||||
|
|
Loading…
Reference in New Issue