Merge remote-tracking branch 'origin/test' into test
This commit is contained in:
commit
2ff0216f68
|
|
@ -0,0 +1,61 @@
|
|||
package cn.ysk.cashier.controller.shop;
|
||||
|
||||
import cn.ysk.cashier.annotation.Log;
|
||||
import cn.ysk.cashier.annotation.rest.AnonymousGetMapping;
|
||||
import cn.ysk.cashier.dto.shop.TbShopPermissionDto;
|
||||
import cn.ysk.cashier.service.TbShopPermissionService;
|
||||
import cn.ysk.cashier.service.TbShopStaffPermissionService;
|
||||
import io.swagger.annotations.Api;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@Api(tags = "歌曲管理")
|
||||
@RequestMapping("/api/tbShopPermission")
|
||||
public class TbShopPermissionController {
|
||||
private final TbShopPermissionService shopPermissionService;
|
||||
|
||||
private final TbShopStaffPermissionService shopStaffPermissionService;
|
||||
|
||||
@PostMapping()
|
||||
@Log("新增店铺权限:#permissionDto.label")
|
||||
public ResponseEntity<Object> insertShopPermission(@RequestBody TbShopPermissionDto permissionDto) {
|
||||
return shopPermissionService.insert(permissionDto);
|
||||
}
|
||||
|
||||
@PutMapping()
|
||||
@Log("修改店铺权限:#permissionDto.label")
|
||||
public ResponseEntity<Object> updateShopPermission(@RequestBody TbShopPermissionDto permissionDto) {
|
||||
return shopPermissionService.update(permissionDto);
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
@Log("删除店铺权限:#id")
|
||||
public ResponseEntity<Object> deleteShopPermission(@PathVariable Integer id) {
|
||||
return shopPermissionService.delete(id);
|
||||
}
|
||||
|
||||
@GetMapping("/list")
|
||||
public ResponseEntity<Object> getShopPermissionList() {
|
||||
List<TbShopPermissionDto> permissionList = shopPermissionService.getShopPermissionList();
|
||||
return ResponseEntity.ok(permissionList);
|
||||
}
|
||||
|
||||
@GetMapping("/hasPermission")
|
||||
@AnonymousGetMapping
|
||||
public ResponseEntity<Object> hasPermission(Integer userId, String code) {
|
||||
boolean hasPermission = shopStaffPermissionService.userHasPermission(userId, code);
|
||||
return ResponseEntity.ok(hasPermission);
|
||||
}
|
||||
|
||||
@GetMapping("/staffPermissionList")
|
||||
@AnonymousGetMapping
|
||||
public ResponseEntity<Object> getStaffPermissionList(Integer userId) {
|
||||
return ResponseEntity.ok(shopStaffPermissionService.getStaffPermissionList(userId));
|
||||
}
|
||||
}
|
||||
|
|
@ -23,6 +23,7 @@ import lombok.Data;
|
|||
import javax.persistence.Column;
|
||||
import java.math.BigDecimal;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
|
|
@ -84,4 +85,6 @@ public class TbPlussShopStaffDto implements Serializable {
|
|||
private Long updatedAt;
|
||||
|
||||
private String type;
|
||||
|
||||
private List<TbShopPermissionDto> permissions;
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
package cn.ysk.cashier.dto.shop;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class TbShopPermissionDto {
|
||||
private Integer id;
|
||||
//权限类型:staff 员工,
|
||||
private String type;
|
||||
//权限名称
|
||||
private String label;
|
||||
//权限code,为了区分采用汉语拼音
|
||||
private String code;
|
||||
//层级
|
||||
private Integer level;
|
||||
//上级ID
|
||||
private Integer parentId;
|
||||
//是否重要: 重要对应页面红色
|
||||
private Integer isImportant;
|
||||
//排序
|
||||
private Integer sort;
|
||||
|
||||
private Integer hasPermission;
|
||||
|
||||
private List<TbShopPermissionDto> children;
|
||||
}
|
||||
|
|
@ -0,0 +1,119 @@
|
|||
package cn.ysk.cashier.entity;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.activerecord.Model;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* (TbShopPermission)表实体类
|
||||
*
|
||||
* @author makejava
|
||||
* @since 2024-09-14 10:53:11
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class TbShopPermission extends Model<TbShopPermission> {
|
||||
|
||||
private Integer id;
|
||||
//权限类型:staff 员工,
|
||||
private String type;
|
||||
//权限名称
|
||||
private String label;
|
||||
//权限code,为了区分采用汉语拼音
|
||||
private String code;
|
||||
//层级
|
||||
private Integer level;
|
||||
//上级ID
|
||||
private Integer parentId;
|
||||
//是否重要: 重要对应页面红色
|
||||
private Integer isImportant;
|
||||
//排序
|
||||
private Integer sort;
|
||||
|
||||
private Date createTime;
|
||||
|
||||
private Date updateTime;
|
||||
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
public void setLabel(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public Integer getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
public void setLevel(Integer level) {
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
public Integer getParentId() {
|
||||
return parentId;
|
||||
}
|
||||
|
||||
public void setParentId(Integer parentId) {
|
||||
this.parentId = parentId;
|
||||
}
|
||||
|
||||
public Integer getIsImportant() {
|
||||
return isImportant;
|
||||
}
|
||||
|
||||
public void setIsImportant(Integer isImportant) {
|
||||
this.isImportant = isImportant;
|
||||
}
|
||||
|
||||
public Integer getSort() {
|
||||
return sort;
|
||||
}
|
||||
|
||||
public void setSort(Integer sort) {
|
||||
this.sort = sort;
|
||||
}
|
||||
|
||||
public Date getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setCreateTime(Date createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
|
||||
public Date getUpdateTime() {
|
||||
return updateTime;
|
||||
}
|
||||
|
||||
public void setUpdateTime(Date updateTime) {
|
||||
this.updateTime = updateTime;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
package cn.ysk.cashier.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.activerecord.Model;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 店铺员工权限关联表(TbShopStaffPermission)表实体类
|
||||
*
|
||||
* @author makejava
|
||||
* @since 2024-09-14 10:54:00
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class TbShopStaffPermission extends Model<TbShopStaffPermission> {
|
||||
|
||||
private Integer id;
|
||||
//权限ID
|
||||
private Integer permissionId;
|
||||
//员工ID
|
||||
private Integer staffId;
|
||||
//店铺ID
|
||||
private Integer shopId;
|
||||
//用户ID
|
||||
private Integer userId;
|
||||
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Integer getPermissionId() {
|
||||
return permissionId;
|
||||
}
|
||||
|
||||
public void setPermissionId(Integer permissionId) {
|
||||
this.permissionId = permissionId;
|
||||
}
|
||||
|
||||
public Integer getStaffId() {
|
||||
return staffId;
|
||||
}
|
||||
|
||||
public void setStaffId(Integer staffId) {
|
||||
this.staffId = staffId;
|
||||
}
|
||||
|
||||
public Integer getShopId() {
|
||||
return shopId;
|
||||
}
|
||||
|
||||
public void setShopId(Integer shopId) {
|
||||
this.shopId = shopId;
|
||||
}
|
||||
|
||||
public Integer getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setUserId(Integer userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package cn.ysk.cashier.mybatis.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import cn.ysk.cashier.entity.TbShopPermission;
|
||||
|
||||
/**
|
||||
* (TbShopPermission)表数据库访问层
|
||||
*
|
||||
* @author makejava
|
||||
* @since 2024-09-14 10:53:11
|
||||
*/
|
||||
public interface TbShopPermissionMapper extends BaseMapper<TbShopPermission> {
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package cn.ysk.cashier.mybatis.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import cn.ysk.cashier.entity.TbShopStaffPermission;
|
||||
|
||||
/**
|
||||
* 店铺员工权限关联表(TbShopStaffPermission)表数据库访问层
|
||||
*
|
||||
* @author makejava
|
||||
* @since 2024-09-14 10:54:00
|
||||
*/
|
||||
public interface TbShopStaffPermissionMapper extends BaseMapper<TbShopStaffPermission> {
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -15,6 +15,7 @@
|
|||
*/
|
||||
package cn.ysk.cashier.pojo.shop;
|
||||
|
||||
import cn.ysk.cashier.dto.shop.TbShopPermissionDto;
|
||||
import cn.ysk.cashier.system.service.dto.RoleSmallDto;
|
||||
import lombok.Data;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
|
|
@ -23,6 +24,7 @@ import cn.hutool.core.bean.copier.CopyOptions;
|
|||
import javax.persistence.*;
|
||||
import java.math.BigDecimal;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @website https://eladmin.vip
|
||||
|
|
@ -102,6 +104,9 @@ public class TbPlussShopStaff implements Serializable {
|
|||
@Transient
|
||||
private String phone;
|
||||
|
||||
@Transient
|
||||
List<TbShopPermissionDto> permissions;
|
||||
|
||||
public void copy(TbPlussShopStaff source){
|
||||
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,29 @@
|
|||
package cn.ysk.cashier.service;
|
||||
|
||||
import cn.ysk.cashier.dto.shop.TbShopPermissionDto;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import cn.ysk.cashier.entity.TbShopPermission;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* (TbShopPermission)表服务接口
|
||||
*
|
||||
* @author makejava
|
||||
* @since 2024-09-14 10:53:11
|
||||
*/
|
||||
public interface TbShopPermissionService extends IService<TbShopPermission> {
|
||||
|
||||
TbShopPermission queryByCode(String code);
|
||||
|
||||
ResponseEntity<Object> insert(TbShopPermissionDto permissionDto);
|
||||
|
||||
ResponseEntity<Object> update(TbShopPermissionDto permissionDto);
|
||||
|
||||
ResponseEntity<Object> delete(Integer id);
|
||||
|
||||
List<TbShopPermissionDto> getShopPermissionList();
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
package cn.ysk.cashier.service;
|
||||
|
||||
import cn.ysk.cashier.dto.shop.TbShopPermissionDto;
|
||||
import cn.ysk.cashier.mybatis.mapper.TbShopStaffPermissionMapper;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import cn.ysk.cashier.entity.TbShopStaffPermission;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 店铺员工权限关联表(TbShopStaffPermission)表服务接口
|
||||
*
|
||||
* @author makejava
|
||||
* @since 2024-09-14 10:54:00
|
||||
*/
|
||||
public interface TbShopStaffPermissionService extends IService<TbShopStaffPermission> {
|
||||
|
||||
boolean userHasPermission(Integer userId, String permissionCode);
|
||||
|
||||
List<TbShopPermissionDto> getStaffPermissionList(Integer userId);
|
||||
|
||||
void updateStaffPermission(Integer userId, Integer shopId, Integer staffId, List<TbShopPermissionDto> permissionIds);
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,136 @@
|
|||
package cn.ysk.cashier.service.impl;
|
||||
|
||||
import cn.ysk.cashier.dto.shop.TbShopPermissionDto;
|
||||
import cn.ysk.cashier.mybatis.mapper.TbShopPermissionMapper;
|
||||
import cn.ysk.cashier.utils.StringUtils;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import cn.ysk.cashier.entity.TbShopPermission;
|
||||
import cn.ysk.cashier.service.TbShopPermissionService;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* (TbShopPermission)表服务实现类
|
||||
*
|
||||
* @author makejava
|
||||
* @since 2024-09-14 10:53:11
|
||||
*/
|
||||
@Service("tbShopPermissionService")
|
||||
public class TbShopPermissionServiceImpl extends ServiceImpl<TbShopPermissionMapper, TbShopPermission> implements TbShopPermissionService {
|
||||
|
||||
@Override
|
||||
public TbShopPermission queryByCode(String code) {
|
||||
QueryWrapper<TbShopPermission> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("code", code);
|
||||
return this.getOne(queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Object> insert(TbShopPermissionDto permissionDto) {
|
||||
// 校验类型和code是否已存在
|
||||
if (this.checkTypeAndCodeExist(permissionDto.getType(), permissionDto.getCode(), null)) {
|
||||
return ResponseEntity.badRequest().body("类型和code已存在");
|
||||
}
|
||||
|
||||
TbShopPermission permission = new TbShopPermission();
|
||||
permission.setType(permissionDto.getType());
|
||||
permission.setLabel(permissionDto.getLabel());
|
||||
permission.setCode(permissionDto.getCode());
|
||||
permission.setIsImportant(permissionDto.getIsImportant());
|
||||
permission.setSort(permissionDto.getSort());
|
||||
permission.setLevel(permissionDto.getLevel());
|
||||
permission.setParentId(permissionDto.getParentId());
|
||||
permission.setCreateTime(new Date());
|
||||
permission.setUpdateTime(new Date());
|
||||
|
||||
this.save(permission);
|
||||
|
||||
return ResponseEntity.ok("新增成功");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Object> update(TbShopPermissionDto permissionDto) {
|
||||
// 检查记录是否存在
|
||||
TbShopPermission permission = this.getById(permissionDto.getId());
|
||||
if (permission == null) {
|
||||
return ResponseEntity.badRequest().body("记录不存在");
|
||||
}
|
||||
|
||||
// 校验类型和code是否已存在
|
||||
if (this.checkTypeAndCodeExist(permissionDto.getType(), permissionDto.getCode(), permissionDto.getId())) {
|
||||
return ResponseEntity.badRequest().body("类型和code已存在");
|
||||
}
|
||||
|
||||
if (StringUtils.isNotBlank(permission.getType())) permission.setType(permissionDto.getType());
|
||||
if (StringUtils.isNotBlank(permission.getLabel())) permission.setLabel(permissionDto.getLabel());
|
||||
if (StringUtils.isNotBlank(permission.getCode())) permission.setCode(permissionDto.getCode());
|
||||
if (permissionDto.getIsImportant() != null) permission.setIsImportant(permissionDto.getIsImportant());
|
||||
if (permissionDto.getSort() != null) permission.setSort(permissionDto.getSort());
|
||||
if (permissionDto.getLevel() != null) permission.setLevel(permissionDto.getLevel());
|
||||
if (permissionDto.getParentId() != null) permission.setParentId(permissionDto.getParentId());
|
||||
permission.setUpdateTime(new Date());
|
||||
|
||||
this.updateById(permission);
|
||||
|
||||
return ResponseEntity.ok("修改成功");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Object> delete(Integer id) {
|
||||
// 检查记录是否存在
|
||||
TbShopPermission permission = this.getById(id);
|
||||
if (permission == null) {
|
||||
return ResponseEntity.badRequest().body("记录不存在");
|
||||
}
|
||||
|
||||
this.removeById(id);
|
||||
|
||||
return ResponseEntity.ok("删除成功");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TbShopPermissionDto> getShopPermissionList() {
|
||||
// 查询level为1的权限
|
||||
QueryWrapper<TbShopPermission> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("level", 1);
|
||||
queryWrapper.orderByAsc("sort");
|
||||
List<TbShopPermission> list = this.list(queryWrapper);
|
||||
|
||||
List<TbShopPermissionDto> permissionDtoList = new ArrayList<>();
|
||||
// 查询子权限
|
||||
for (TbShopPermission permission : list) {
|
||||
String jsonString = JSONObject.toJSONString(permission);
|
||||
TbShopPermissionDto permissionDto = JSONObject.parseObject(jsonString, TbShopPermissionDto.class);
|
||||
|
||||
QueryWrapper<TbShopPermission> wrapper = new QueryWrapper<>();
|
||||
wrapper.eq("parent_id", permission.getId());
|
||||
wrapper.orderByAsc("sort");
|
||||
List<TbShopPermission> children = this.list(wrapper);
|
||||
|
||||
String listStr = JSONObject.toJSONString(children);
|
||||
List<TbShopPermissionDto> childrenDto = JSONObject.parseArray(listStr, TbShopPermissionDto.class);
|
||||
permissionDto.setChildren(childrenDto);
|
||||
|
||||
permissionDtoList.add(permissionDto);
|
||||
}
|
||||
|
||||
return permissionDtoList;
|
||||
}
|
||||
|
||||
private boolean checkTypeAndCodeExist(String type, String code, Integer id) {
|
||||
QueryWrapper<TbShopPermission> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("type", type);
|
||||
queryWrapper.eq("code", code);
|
||||
if (id != null) {
|
||||
queryWrapper.ne("id", id);
|
||||
}
|
||||
return this.count(queryWrapper) > 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,104 @@
|
|||
package cn.ysk.cashier.service.impl;
|
||||
|
||||
import cn.ysk.cashier.dto.shop.TbShopPermissionDto;
|
||||
import cn.ysk.cashier.entity.TbShopPermission;
|
||||
import cn.ysk.cashier.service.TbShopPermissionService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import cn.ysk.cashier.mybatis.mapper.TbShopStaffPermissionMapper;
|
||||
import cn.ysk.cashier.entity.TbShopStaffPermission;
|
||||
import cn.ysk.cashier.service.TbShopStaffPermissionService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.transaction.Transactional;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 店铺员工权限关联表(TbShopStaffPermission)表服务实现类
|
||||
*
|
||||
* @author makejava
|
||||
* @since 2024-09-14 10:54:01
|
||||
*/
|
||||
@Service("tbShopStaffPermissionService")
|
||||
public class TbShopStaffPermissionServiceImpl extends ServiceImpl<TbShopStaffPermissionMapper, TbShopStaffPermission> implements TbShopStaffPermissionService {
|
||||
|
||||
@Autowired
|
||||
private TbShopPermissionService shopPermissionService;
|
||||
|
||||
@Override
|
||||
public boolean userHasPermission(Integer userId, String permissionCode) {
|
||||
TbShopPermission permission = shopPermissionService.queryByCode(permissionCode);
|
||||
if (permission == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
QueryWrapper<TbShopStaffPermission> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("user_id", userId);
|
||||
queryWrapper.eq("permission_id", permission.getId());
|
||||
TbShopStaffPermission staffPermission = this.getOne(queryWrapper);
|
||||
|
||||
return staffPermission != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TbShopPermissionDto> getStaffPermissionList(Integer userId) {
|
||||
List<TbShopPermissionDto> permissionList = shopPermissionService.getShopPermissionList();
|
||||
|
||||
QueryWrapper<TbShopStaffPermission> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("user_id", userId);
|
||||
List<TbShopStaffPermission> staffPermissions = this.list(queryWrapper);
|
||||
|
||||
List<Integer> permissionIds = staffPermissions.stream().collect(ArrayList::new, (list, staffPermission) -> list.add(staffPermission.getPermissionId()), ArrayList::addAll);
|
||||
|
||||
for (TbShopPermissionDto permission : permissionList) {
|
||||
permission.setHasPermission(permissionIds.contains(permission.getId()) ? 1 : 0);
|
||||
|
||||
if (permission.getChildren().isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (TbShopPermissionDto child : permission.getChildren()) {
|
||||
child.setHasPermission(permissionIds.contains(child.getId()) ? 1 : 0);
|
||||
}
|
||||
}
|
||||
return permissionList;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void updateStaffPermission(Integer userId, Integer shopId, Integer staffId, List<TbShopPermissionDto> permissionIds) {
|
||||
QueryWrapper<TbShopStaffPermission> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("user_id", userId);
|
||||
this.remove(queryWrapper);
|
||||
|
||||
List<TbShopStaffPermission> staffPermissions = new ArrayList<>();
|
||||
for (TbShopPermissionDto permission : permissionIds) {
|
||||
TbShopStaffPermission staffPermission = new TbShopStaffPermission();
|
||||
staffPermission.setUserId(userId);
|
||||
staffPermission.setPermissionId(permission.getId());
|
||||
staffPermission.setStaffId(staffId);
|
||||
staffPermission.setShopId(shopId);
|
||||
staffPermissions.add(staffPermission);
|
||||
|
||||
if (permission.getChildren().isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (TbShopPermissionDto child : permission.getChildren()) {
|
||||
TbShopStaffPermission childStaffPermission = new TbShopStaffPermission();
|
||||
childStaffPermission.setUserId(userId);
|
||||
childStaffPermission.setPermissionId(child.getId());
|
||||
staffPermission.setStaffId(staffId);
|
||||
staffPermission.setShopId(shopId);
|
||||
staffPermissions.add(childStaffPermission);
|
||||
}
|
||||
}
|
||||
|
||||
this.saveBatch(staffPermissions);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -15,9 +15,11 @@
|
|||
*/
|
||||
package cn.ysk.cashier.service.impl.shopimpl;
|
||||
|
||||
import cn.ysk.cashier.dto.shop.TbShopPermissionDto;
|
||||
import cn.ysk.cashier.exception.BadRequestException;
|
||||
import cn.ysk.cashier.exception.EntityExistException;
|
||||
import cn.ysk.cashier.pojo.shop.TbPlussShopStaff;
|
||||
import cn.ysk.cashier.service.TbShopStaffPermissionService;
|
||||
import cn.ysk.cashier.system.domain.Dept;
|
||||
import cn.ysk.cashier.system.domain.Job;
|
||||
import cn.ysk.cashier.system.domain.Role;
|
||||
|
|
@ -64,6 +66,8 @@ public class TbPlussShopStaffServiceImpl implements TbPlussShopStaffService {
|
|||
private final PasswordEncoder passwordEncoder;
|
||||
private final UserService userService;
|
||||
|
||||
private final TbShopStaffPermissionService shopStaffPermissionService;
|
||||
|
||||
// 正则表达式:(\u4e00-\u9fa5) 表示匹配一个中文字符,.* 表示匹配零个或多个任意字符
|
||||
private final Pattern pattern = Pattern.compile("[\\u4e00-\\u9fa5]");
|
||||
|
||||
|
|
@ -91,6 +95,9 @@ public class TbPlussShopStaffServiceImpl implements TbPlussShopStaffService {
|
|||
}
|
||||
dto.setPhone(userDto.getPhone());
|
||||
dto.setPassword("");//不返回密码
|
||||
|
||||
List<TbShopPermissionDto> permissionList = shopStaffPermissionService.getStaffPermissionList(userDto.getId().intValue());
|
||||
dto.setPermissions(permissionList);
|
||||
return dto;
|
||||
}
|
||||
|
||||
|
|
@ -147,6 +154,9 @@ public class TbPlussShopStaffServiceImpl implements TbPlussShopStaffService {
|
|||
jobs.add(job);
|
||||
user.setJobs(jobs);
|
||||
userRepository.save(user);
|
||||
|
||||
shopStaffPermissionService.updateStaffPermission(user.getId().intValue(),
|
||||
Integer.valueOf(resources.getShopId()), resources.getId(), resources.getPermissions());
|
||||
return tbPlussShopStaffMapper.toDto(tbPlussShopStaffRepository.save(resources));
|
||||
}
|
||||
|
||||
|
|
@ -187,6 +197,9 @@ public class TbPlussShopStaffServiceImpl implements TbPlussShopStaffService {
|
|||
}
|
||||
sysUser.setPhone(resources.getPhone());
|
||||
userRepository.save(sysUser);
|
||||
|
||||
shopStaffPermissionService.updateStaffPermission(sysUser.getId().intValue(),
|
||||
Integer.valueOf(resources.getShopId()), resources.getId(), resources.getPermissions());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -15,12 +15,14 @@
|
|||
*/
|
||||
package cn.ysk.cashier.system.service.dto;
|
||||
|
||||
import cn.ysk.cashier.dto.shop.TbShopPermissionDto;
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import cn.ysk.cashier.base.BaseDTO;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue