25 changed files with 797 additions and 89 deletions
@ -0,0 +1,93 @@ |
|||
package com.qs.serve.modules.sys.controller; |
|||
|
|||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|||
import com.qs.serve.common.model.annotation.SysLog; |
|||
import com.qs.serve.common.model.dto.PageVo; |
|||
import com.qs.serve.common.model.dto.R; |
|||
import com.qs.serve.common.model.enums.BizType; |
|||
import com.qs.serve.common.model.enums.SystemModule; |
|||
import com.qs.serve.common.util.PageUtil; |
|||
import com.qs.serve.common.util.CopierUtil; |
|||
import com.qs.serve.common.util.StringUtils; |
|||
import lombok.AllArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.security.access.prepost.PreAuthorize; |
|||
import org.springframework.web.bind.annotation.*; |
|||
|
|||
import com.qs.serve.modules.sys.entity.so.SysPostUserSo; |
|||
import com.qs.serve.modules.sys.entity.bo.SysPostUserBo; |
|||
import com.qs.serve.modules.sys.entity.SysPostUser; |
|||
import com.qs.serve.modules.sys.service.SysPostUserService; |
|||
|
|||
import javax.validation.Valid; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* 系统 系统职务 |
|||
* @author YenHex |
|||
* @since 2023-04-27 |
|||
*/ |
|||
@Slf4j |
|||
@AllArgsConstructor |
|||
@RestController |
|||
@RequestMapping("sys/postUser") |
|||
public class SysPostUserController { |
|||
|
|||
private SysPostUserService sysPostUserService; |
|||
|
|||
|
|||
/** |
|||
* 翻页 |
|||
* @param param |
|||
* @return |
|||
*/ |
|||
@GetMapping("/page") |
|||
public R<PageVo<SysPostUser>> getPage(SysPostUserSo param){ |
|||
SysPostUser entity = CopierUtil.copy(param,new SysPostUser()); |
|||
LambdaQueryWrapper<SysPostUser> lqw = new LambdaQueryWrapper<>(entity); |
|||
PageUtil.startPage(); |
|||
List<SysPostUser> list = sysPostUserService.list(lqw); |
|||
return R.byPageHelperList(list); |
|||
} |
|||
|
|||
/** |
|||
* ID查询 |
|||
* @param id |
|||
* @return |
|||
*/ |
|||
//@GetMapping("/getById/{id}")
|
|||
@SysLog(module = SystemModule.SYSTEM, title = "系统职务", biz = BizType.QUERY) |
|||
public R<SysPostUser> getById(@PathVariable("id") String id){ |
|||
SysPostUser sysPostUser = sysPostUserService.getById(id); |
|||
return R.ok(sysPostUser); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 绑定用户与职务 |
|||
* @param param |
|||
* @return |
|||
*/ |
|||
@PostMapping("/bind") |
|||
@SysLog(module = SystemModule.SYSTEM, title = "系统职务", biz = BizType.INSERT) |
|||
public R<?> save(@RequestBody @Valid SysPostUserBo param){ |
|||
sysPostUserService.bind(param); |
|||
return R.ok(); |
|||
} |
|||
|
|||
/** |
|||
* 删除 |
|||
* @param ids |
|||
* @return |
|||
*/ |
|||
@DeleteMapping("/deleteById/{ids}") |
|||
@SysLog(module = SystemModule.SYSTEM, title = "系统职务", biz = BizType.DELETE) |
|||
public R<?> deleteById(@PathVariable("ids") String ids){ |
|||
List<Long> idsLong = StringUtils.splitIdLong(ids); |
|||
boolean result = sysPostUserService.removeByIds(idsLong); |
|||
return R.isTrue(result); |
|||
} |
|||
|
|||
|
|||
} |
|||
|
@ -0,0 +1,132 @@ |
|||
package com.qs.serve.modules.sys.entity; |
|||
|
|||
import java.time.LocalDate; |
|||
import java.io.Serializable; |
|||
import java.math.BigDecimal; |
|||
import java.time.LocalDateTime; |
|||
|
|||
import com.baomidou.mybatisplus.annotation.*; |
|||
import com.fasterxml.jackson.annotation.JsonFormat; |
|||
import com.fasterxml.jackson.annotation.JsonIgnore; |
|||
import com.fasterxml.jackson.annotation.JsonProperty; |
|||
import lombok.Data; |
|||
import org.hibernate.validator.constraints.Length; |
|||
import org.springframework.format.annotation.DateTimeFormat; |
|||
|
|||
import javax.validation.constraints.NotNull; |
|||
import javax.validation.constraints.NotBlank; |
|||
|
|||
/** |
|||
* 系统职务 实体类 |
|||
* @author YenHex |
|||
* @since 2023-04-27 |
|||
*/ |
|||
@Data |
|||
@TableName("sys_post_user") |
|||
public class SysPostUser implements Serializable { |
|||
|
|||
private static final long serialVersionUID = 1L; |
|||
|
|||
/** id */ |
|||
@TableId(type = IdType.AUTO) |
|||
private Long id; |
|||
|
|||
/** 用户id */ |
|||
@Length(max = 255,message = "用户id长度不能超过255字") |
|||
private String userId; |
|||
|
|||
/** 用户编码 */ |
|||
@Length(max = 255,message = "用户编码长度不能超过255字") |
|||
@TableField(condition = SqlCondition.LIKE) |
|||
private String userCode; |
|||
|
|||
/** 用户名称 */ |
|||
@Length(max = 255,message = "用户名称长度不能超过255字") |
|||
@TableField(condition = SqlCondition.LIKE) |
|||
private String userName; |
|||
|
|||
/** 岗位id */ |
|||
@Length(max = 64,message = "岗位id长度不能超过64字") |
|||
private String postId; |
|||
|
|||
/** 岗位名称 */ |
|||
@Length(max = 20,message = "岗位名称长度不能超过20字") |
|||
@TableField(condition = SqlCondition.LIKE) |
|||
private String postName; |
|||
|
|||
/** 岗位编码 */ |
|||
@Length(max = 30,message = "岗位编码长度不能超过30字") |
|||
@TableField(condition = SqlCondition.LIKE) |
|||
private String postCode; |
|||
|
|||
/** 岗位pid */ |
|||
@Length(max = 64,message = "岗位pid长度不能超过64字") |
|||
private String pid; |
|||
|
|||
/** id路径 */ |
|||
@Length(max = 4255,message = "id路径长度不能超过4255字") |
|||
private String pathIds; |
|||
|
|||
/** 名称路径 */ |
|||
@Length(max = 4255,message = "名称路径长度不能超过4255字") |
|||
private String pathNames; |
|||
|
|||
/** 备注 */ |
|||
@Length(max = 255,message = "备注长度不能超过255字") |
|||
private String remark; |
|||
|
|||
/** 创建时间 */ |
|||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
|||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") |
|||
@TableField(fill = FieldFill.INSERT) |
|||
private LocalDateTime createTime; |
|||
|
|||
/** 创建人 */ |
|||
@TableField(fill = FieldFill.INSERT) |
|||
private String createBy; |
|||
|
|||
/** 更新时间 */ |
|||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
|||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") |
|||
@TableField(fill = FieldFill.UPDATE) |
|||
private LocalDateTime updateTime; |
|||
|
|||
/** 更新人 */ |
|||
@TableField(fill = FieldFill.UPDATE) |
|||
private String updateBy; |
|||
|
|||
/** 租户id */ |
|||
@JsonIgnore |
|||
@JsonProperty |
|||
private String tenantId; |
|||
|
|||
/** 删除标识 */ |
|||
@JsonIgnore |
|||
@JsonProperty |
|||
private Boolean delFlag; |
|||
|
|||
|
|||
public static SysPostUser toNewObject(SysPostUser source){ |
|||
SysPostUser postUser = new SysPostUser(); |
|||
postUser.setId(source.getId()); |
|||
postUser.setUserId(source.getUserId()); |
|||
postUser.setUserCode(source.getUserCode()); |
|||
postUser.setUserName(source.getUserName()); |
|||
postUser.setPostId(source.getPostId()); |
|||
postUser.setPostName(source.getPostName()); |
|||
postUser.setPostCode(source.getPostCode()); |
|||
postUser.setPid(source.getPid()); |
|||
postUser.setPathIds(source.getPathIds()); |
|||
postUser.setPathNames(source.getPathNames()); |
|||
postUser.setRemark(source.getRemark()); |
|||
postUser.setCreateTime(source.getCreateTime()); |
|||
postUser.setCreateBy(source.getCreateBy()); |
|||
postUser.setUpdateTime(source.getUpdateTime()); |
|||
postUser.setUpdateBy(source.getUpdateBy()); |
|||
postUser.setTenantId(source.getTenantId()); |
|||
postUser.setDelFlag(source.getDelFlag()); |
|||
return postUser; |
|||
} |
|||
|
|||
} |
|||
|
@ -0,0 +1,43 @@ |
|||
package com.qs.serve.modules.sys.entity.bo; |
|||
|
|||
import java.time.LocalDate; |
|||
import java.io.Serializable; |
|||
import java.math.BigDecimal; |
|||
import java.time.LocalDateTime; |
|||
import java.util.List; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonFormat; |
|||
import com.fasterxml.jackson.annotation.JsonIgnore; |
|||
import com.fasterxml.jackson.annotation.JsonProperty; |
|||
import lombok.Data; |
|||
import org.hibernate.validator.constraints.Length; |
|||
import org.springframework.format.annotation.DateTimeFormat; |
|||
|
|||
import javax.validation.constraints.NotNull; |
|||
import javax.validation.constraints.NotBlank; |
|||
|
|||
/** |
|||
* 系统职务 Bo |
|||
* @author YenHex |
|||
* @since 2023-04-27 |
|||
*/ |
|||
@Data |
|||
public class SysPostUserBo implements Serializable { |
|||
|
|||
private static final long serialVersionUID = 1L; |
|||
|
|||
/** 用户id */ |
|||
private List<String> userIds; |
|||
|
|||
/** 岗位id */ |
|||
private List<String> postIds; |
|||
|
|||
/** |
|||
* 0:添加不进行删除 |
|||
* 1:以`用户id`为参照物,删除历史`岗位id`,并重新添加新的`岗位id` |
|||
* 2:以`岗位id`为参照物,删除历史`用户id`,并重新添加新的`用户id` |
|||
*/ |
|||
private Integer saveType; |
|||
|
|||
} |
|||
|
@ -0,0 +1,86 @@ |
|||
package com.qs.serve.modules.sys.entity.so; |
|||
|
|||
import java.time.LocalDate; |
|||
import java.io.Serializable; |
|||
import java.math.BigDecimal; |
|||
import java.time.LocalDateTime; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonFormat; |
|||
import com.fasterxml.jackson.annotation.JsonIgnore; |
|||
import com.fasterxml.jackson.annotation.JsonProperty; |
|||
import lombok.Data; |
|||
import org.hibernate.validator.constraints.Length; |
|||
import org.springframework.format.annotation.DateTimeFormat; |
|||
|
|||
import javax.validation.constraints.NotNull; |
|||
import javax.validation.constraints.NotBlank; |
|||
|
|||
/** |
|||
* 系统职务 查询参数 |
|||
* @author YenHex |
|||
* @since 2023-04-27 |
|||
*/ |
|||
@Data |
|||
public class SysPostUserSo implements Serializable { |
|||
|
|||
private static final long serialVersionUID = 1L; |
|||
|
|||
/** id */ |
|||
private Long id; |
|||
|
|||
/** 用户id */ |
|||
private String userId; |
|||
|
|||
/** 用户编码 */ |
|||
private String userCode; |
|||
|
|||
/** 用户名称 */ |
|||
private String userName; |
|||
|
|||
/** 岗位id */ |
|||
private String postId; |
|||
|
|||
/** 岗位名称 */ |
|||
private String postName; |
|||
|
|||
/** 岗位编码 */ |
|||
private String postCode; |
|||
|
|||
/** 岗位pid */ |
|||
private String pid; |
|||
|
|||
/** id路径 */ |
|||
private String pathIds; |
|||
|
|||
/** 名称路径 */ |
|||
private String pathNames; |
|||
|
|||
/** 备注 */ |
|||
private String remark; |
|||
|
|||
/** 创建时间 */ |
|||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
|||
private LocalDateTime createTime; |
|||
|
|||
/** 创建人 */ |
|||
private String createBy; |
|||
|
|||
/** 更新时间 */ |
|||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
|||
private LocalDateTime updateTime; |
|||
|
|||
/** 更新人 */ |
|||
private String updateBy; |
|||
|
|||
/** 租户id */ |
|||
@JsonIgnore |
|||
@JsonProperty |
|||
private String tenantId; |
|||
|
|||
/** 删除标识 */ |
|||
@JsonIgnore |
|||
@JsonProperty |
|||
private Boolean delFlag; |
|||
|
|||
} |
|||
|
@ -0,0 +1,47 @@ |
|||
package com.qs.serve.modules.sys.entity.vo; |
|||
|
|||
import com.baomidou.mybatisplus.annotation.IdType; |
|||
import com.baomidou.mybatisplus.annotation.SqlCondition; |
|||
import com.baomidou.mybatisplus.annotation.TableField; |
|||
import com.baomidou.mybatisplus.annotation.TableId; |
|||
import com.qs.serve.common.model.dto.TreeNode; |
|||
import lombok.Data; |
|||
import org.hibernate.validator.constraints.Length; |
|||
|
|||
/** |
|||
* @author YenHex |
|||
* @since 2023/4/27 |
|||
*/ |
|||
@Data |
|||
public class SysPostTreeVo extends TreeNode { |
|||
|
|||
/** id */ |
|||
@TableId(type = IdType.ASSIGN_UUID) |
|||
private String id; |
|||
|
|||
/** 名称 */ |
|||
@Length(max = 20,message = "名称长度不能超过20字") |
|||
@TableField(condition = SqlCondition.LIKE) |
|||
private String postName; |
|||
|
|||
/** 编码 */ |
|||
@Length(max = 30,message = "编码长度不能超过30字") |
|||
@TableField(condition = SqlCondition.LIKE) |
|||
private String postCode; |
|||
|
|||
private String pid; |
|||
|
|||
/** id路径 */ |
|||
@Length(max = 4255,message = "id路径长度不能超过4255字") |
|||
private String pathIds; |
|||
|
|||
/** 名称路径 */ |
|||
@Length(max = 4255,message = "名称路径长度不能超过4255字") |
|||
@TableField(condition = SqlCondition.LIKE) |
|||
private String pathNames; |
|||
|
|||
/** 备注 */ |
|||
@Length(max = 255,message = "备注长度不能超过255字") |
|||
private String remark; |
|||
|
|||
} |
@ -0,0 +1,14 @@ |
|||
package com.qs.serve.modules.sys.mapper; |
|||
|
|||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
|||
import com.qs.serve.modules.sys.entity.SysPostUser; |
|||
|
|||
/** |
|||
* 系统职务 Mapper |
|||
* @author YenHex |
|||
* @date 2023-04-27 |
|||
*/ |
|||
public interface SysPostUserMapper extends BaseMapper<SysPostUser> { |
|||
|
|||
} |
|||
|
@ -0,0 +1,21 @@ |
|||
package com.qs.serve.modules.sys.service; |
|||
|
|||
import com.baomidou.mybatisplus.extension.service.IService; |
|||
import com.qs.serve.modules.sys.entity.SysPostUser; |
|||
import com.qs.serve.modules.sys.entity.bo.SysPostUserBo; |
|||
import java.util.List; |
|||
/** |
|||
* 系统职务 服务接口 |
|||
* @author YenHex |
|||
* @date 2023-04-27 |
|||
*/ |
|||
public interface SysPostUserService extends IService<SysPostUser> { |
|||
|
|||
List<SysPostUser> listByUserId(String userId); |
|||
|
|||
void updatePathIds(String orgPathIds,String newPathIds,String orgPathNames,String newPathNames); |
|||
|
|||
void bind(SysPostUserBo param); |
|||
|
|||
} |
|||
|
@ -0,0 +1,112 @@ |
|||
package com.qs.serve.modules.sys.service.impl; |
|||
|
|||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|||
import com.qs.serve.common.util.CollectionUtil; |
|||
import com.qs.serve.modules.sys.entity.SysPost; |
|||
import com.qs.serve.modules.sys.entity.SysUser; |
|||
import com.qs.serve.modules.sys.entity.bo.SysPostUserBo; |
|||
import com.qs.serve.modules.sys.mapper.SysPostMapper; |
|||
import com.qs.serve.modules.sys.mapper.SysUserMapper; |
|||
import com.qs.serve.modules.sys.service.SysPostService; |
|||
import com.qs.serve.modules.sys.service.SysUserService; |
|||
import com.qs.serve.modules.tag.entity.TagData; |
|||
import lombok.AllArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.stereotype.Service; |
|||
import com.qs.serve.modules.sys.entity.SysPostUser; |
|||
import com.qs.serve.modules.sys.service.SysPostUserService; |
|||
import com.qs.serve.modules.sys.mapper.SysPostUserMapper; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* 系统职务 服务实现类 |
|||
* @author YenHex |
|||
* @since 2023-04-27 |
|||
*/ |
|||
@Slf4j |
|||
@Service |
|||
@AllArgsConstructor |
|||
public class SysPostUserServiceImpl extends ServiceImpl<SysPostUserMapper,SysPostUser> implements SysPostUserService { |
|||
|
|||
SysPostMapper postMapper; |
|||
SysUserMapper userMapper; |
|||
|
|||
@Override |
|||
public List<SysPostUser> listByUserId(String userId) { |
|||
LambdaQueryWrapper<SysPostUser> lqw = new LambdaQueryWrapper<>(); |
|||
lqw.eq(SysPostUser::getUserId,userId); |
|||
return this.list(lqw); |
|||
} |
|||
|
|||
@Override |
|||
public void updatePathIds(String orgPathIds,String newPathIds,String orgPathNames,String newPathNames){ |
|||
LambdaQueryWrapper<SysPostUser> lqw = new LambdaQueryWrapper<>(); |
|||
lqw.likeRight(SysPostUser::getPathIds,orgPathIds+"_"); |
|||
lqw.select(SysPostUser::getId,SysPostUser::getPathIds,SysPostUser::getPathNames); |
|||
List<SysPostUser> postUserList = this.list(lqw); |
|||
if(CollectionUtil.isNotEmpty(postUserList)){ |
|||
for (SysPostUser postUser : postUserList) { |
|||
postUser.setPathIds(postUser.getPathIds().replace(orgPathIds,newPathIds)); |
|||
postUser.setPostName(postUser.getPathNames().replace(orgPathNames,newPathNames)); |
|||
} |
|||
this.updateBatchById(postUserList); |
|||
} |
|||
} |
|||
|
|||
@Override |
|||
public void bind(SysPostUserBo param) { |
|||
Integer saveType = param.getSaveType()==null?0: param.getSaveType(); |
|||
LambdaQueryWrapper<SysPost> postLqw = new LambdaQueryWrapper<>(); |
|||
postLqw.in(SysPost::getId,param.getUserIds()); |
|||
List<SysPost> postList = postMapper.selectList(postLqw); |
|||
LambdaQueryWrapper<SysUser> userLqw = new LambdaQueryWrapper<>(); |
|||
userLqw.in(SysUser::getId,param.getUserIds()); |
|||
List<SysUser> userList = userMapper.selectList(userLqw); |
|||
if(CollectionUtil.isNotEmpty(postList)&&CollectionUtil.isNotEmpty(userList)){ |
|||
//移除历史数据
|
|||
if (saveType.equals(1)){ |
|||
LambdaQueryWrapper<SysPostUser> lqw = new LambdaQueryWrapper<>(); |
|||
lqw.in(SysPostUser::getUserId,param.getUserIds()); |
|||
this.remove(lqw); |
|||
}else if (saveType.equals(2)){ |
|||
LambdaQueryWrapper<SysPostUser> lqw = new LambdaQueryWrapper<>(); |
|||
lqw.in(SysPostUser::getPostId,param.getPostIds()); |
|||
this.remove(lqw); |
|||
} |
|||
List<SysPostUser> resultList = new ArrayList<>(); |
|||
for (SysUser sysUser : userList) { |
|||
for (SysPost sysPost : postList) { |
|||
//避免重复
|
|||
if(saveType.equals(0)){ |
|||
LambdaQueryWrapper<SysPostUser> lqw = new LambdaQueryWrapper<>(); |
|||
lqw.eq(SysPostUser::getPostId,sysPost.getId()); |
|||
lqw.eq(SysPostUser::getUserId,sysUser.getId()); |
|||
if(this.count(lqw)>0){ |
|||
continue; |
|||
} |
|||
} |
|||
SysPostUser postUser = new SysPostUser(); |
|||
postUser.setUserId(sysUser.getId()); |
|||
postUser.setUserCode(sysUser.getCode()); |
|||
postUser.setUserName(sysUser.getName()); |
|||
postUser.setPostId(sysPost.getId()); |
|||
postUser.setPostName(sysPost.getPostName()); |
|||
postUser.setPostCode(sysPost.getPostCode()); |
|||
postUser.setPid(sysPost.getPid()); |
|||
postUser.setPathIds(sysPost.getPathIds()); |
|||
postUser.setPathNames(sysPost.getPathNames()); |
|||
resultList.add(postUser); |
|||
} |
|||
} |
|||
if(CollectionUtil.isNotEmpty(resultList)){ |
|||
this.saveBatch(resultList); |
|||
} |
|||
} |
|||
|
|||
} |
|||
|
|||
} |
|||
|
Loading…
Reference in new issue