修复几个bug

This commit is contained in:
Richie 2025-04-24 20:18:55 +08:00
parent e33aa7f9ad
commit 1ff73409e8
5 changed files with 528 additions and 191 deletions

View File

@ -40,7 +40,7 @@ public class ShopController extends BaseController {
@GetMapping("/list") @GetMapping("/list")
public TableDataInfo list(ShopBo shop) public TableDataInfo list(ShopBo shop)
{ {
LambdaQueryWrapper<OShop> qw = new LambdaQueryWrapper<OShop>().eq(shop.getPlatform()!=null,OShop::getType,shop.getPlatform()); LambdaQueryWrapper<OShop> qw = new LambdaQueryWrapper<OShop>().eq(shop.getType()!=null,OShop::getType,shop.getType());
List<OShop> list = shopService.list(qw); List<OShop> list = shopService.list(qw);
return getDataTable(list); return getDataTable(list);
} }

View File

@ -20,7 +20,7 @@ public class ShopBo implements Serializable {
/** /**
* 对应第三方平台Id * 对应第三方平台Id
*/ */
private Integer platform; private Integer type;

View File

@ -1,189 +1,189 @@
package cn.qihangerp.sys.common; //package cn.qihangerp.sys.common;
//
import cn.qihangerp.domain.SysDictData; //import cn.qihangerp.domain.SysDictData;
import com.alibaba.fastjson2.JSONArray; //import com.alibaba.fastjson2.JSONArray;
import cn.qihangerp.common.config.RedisCache; //import cn.qihangerp.common.config.RedisCache;
import cn.qihangerp.common.constant.CacheConstants; //import cn.qihangerp.common.constant.CacheConstants;
import cn.qihangerp.common.utils.SpringUtils; //import cn.qihangerp.common.utils.SpringUtils;
import cn.qihangerp.common.utils.StringUtils; //import cn.qihangerp.common.utils.StringUtils;
//
//
import java.util.Collection; //import java.util.Collection;
import java.util.List; //import java.util.List;
//
/** ///**
* 字典工具类 // * 字典工具类
* // *
* @author qihang // * @author qihang
*/ // */
public class DictUtils //public class DictUtils
{ //{
/** // /**
* 分隔符 // * 分隔符
*/ // */
public static final String SEPARATOR = ","; // public static final String SEPARATOR = ",";
//
/** // /**
* 设置字典缓存 // * 设置字典缓存
* // *
* @param key 参数键 // * @param key 参数键
* @param dictDatas 字典数据列表 // * @param dictDatas 字典数据列表
*/ // */
public static void setDictCache(String key, List<SysDictData> dictDatas) // public static void setDictCache(String key, List<SysDictData> dictDatas)
{ // {
SpringUtils.getBean(RedisCache.class).setCacheObject(getCacheKey(key), dictDatas); // SpringUtils.getBean(RedisCache.class).setCacheObject(getCacheKey(key), dictDatas);
} // }
//
/** // /**
* 获取字典缓存 // * 获取字典缓存
* // *
* @param key 参数键 // * @param key 参数键
* @return dictDatas 字典数据列表 // * @return dictDatas 字典数据列表
*/ // */
public static List<SysDictData> getDictCache(String key) // public static List<SysDictData> getDictCache(String key)
{ // {
JSONArray arrayCache = SpringUtils.getBean(RedisCache.class).getCacheObject(getCacheKey(key)); // JSONArray arrayCache = SpringUtils.getBean(RedisCache.class).getCacheObject(getCacheKey(key));
if (StringUtils.isNotNull(arrayCache)) // if (StringUtils.isNotNull(arrayCache))
{ // {
return arrayCache.toList(SysDictData.class); // return arrayCache.toList(SysDictData.class);
} // }
return null; // return null;
} // }
//
/** // /**
* 根据字典类型和字典值获取字典标签 // * 根据字典类型和字典值获取字典标签
* // *
* @param dictType 字典类型 // * @param dictType 字典类型
* @param dictValue 字典值 // * @param dictValue 字典值
* @return 字典标签 // * @return 字典标签
*/ // */
public static String getDictLabel(String dictType, String dictValue) // public static String getDictLabel(String dictType, String dictValue)
{ // {
return getDictLabel(dictType, dictValue, SEPARATOR); // return getDictLabel(dictType, dictValue, SEPARATOR);
} // }
//
/** // /**
* 根据字典类型和字典标签获取字典值 // * 根据字典类型和字典标签获取字典值
* // *
* @param dictType 字典类型 // * @param dictType 字典类型
* @param dictLabel 字典标签 // * @param dictLabel 字典标签
* @return 字典值 // * @return 字典值
*/ // */
public static String getDictValue(String dictType, String dictLabel) // public static String getDictValue(String dictType, String dictLabel)
{ // {
return getDictValue(dictType, dictLabel, SEPARATOR); // return getDictValue(dictType, dictLabel, SEPARATOR);
} // }
//
/** // /**
* 根据字典类型和字典值获取字典标签 // * 根据字典类型和字典值获取字典标签
* // *
* @param dictType 字典类型 // * @param dictType 字典类型
* @param dictValue 字典值 // * @param dictValue 字典值
* @param separator 分隔符 // * @param separator 分隔符
* @return 字典标签 // * @return 字典标签
*/ // */
public static String getDictLabel(String dictType, String dictValue, String separator) // public static String getDictLabel(String dictType, String dictValue, String separator)
{ // {
StringBuilder propertyString = new StringBuilder(); // StringBuilder propertyString = new StringBuilder();
List<SysDictData> datas = getDictCache(dictType); // List<SysDictData> datas = getDictCache(dictType);
//
if (StringUtils.isNotNull(datas)) // if (StringUtils.isNotNull(datas))
{ // {
if (StringUtils.containsAny(separator, dictValue)) // if (StringUtils.containsAny(separator, dictValue))
{ // {
for (SysDictData dict : datas) // for (SysDictData dict : datas)
{ // {
for (String value : dictValue.split(separator)) // for (String value : dictValue.split(separator))
{ // {
if (value.equals(dict.getDictValue())) // if (value.equals(dict.getDictValue()))
{ // {
propertyString.append(dict.getDictLabel()).append(separator); // propertyString.append(dict.getDictLabel()).append(separator);
break; // break;
} // }
} // }
} // }
} // }
else // else
{ // {
for (SysDictData dict : datas) // for (SysDictData dict : datas)
{ // {
if (dictValue.equals(dict.getDictValue())) // if (dictValue.equals(dict.getDictValue()))
{ // {
return dict.getDictLabel(); // return dict.getDictLabel();
} // }
} // }
} // }
} // }
return StringUtils.stripEnd(propertyString.toString(), separator); // return StringUtils.stripEnd(propertyString.toString(), separator);
} // }
//
/** // /**
* 根据字典类型和字典标签获取字典值 // * 根据字典类型和字典标签获取字典值
* // *
* @param dictType 字典类型 // * @param dictType 字典类型
* @param dictLabel 字典标签 // * @param dictLabel 字典标签
* @param separator 分隔符 // * @param separator 分隔符
* @return 字典值 // * @return 字典值
*/ // */
public static String getDictValue(String dictType, String dictLabel, String separator) // public static String getDictValue(String dictType, String dictLabel, String separator)
{ // {
StringBuilder propertyString = new StringBuilder(); // StringBuilder propertyString = new StringBuilder();
List<SysDictData> datas = getDictCache(dictType); // List<SysDictData> datas = getDictCache(dictType);
//
if (StringUtils.containsAny(separator, dictLabel) && StringUtils.isNotEmpty(datas)) // if (StringUtils.containsAny(separator, dictLabel) && StringUtils.isNotEmpty(datas))
{ // {
for (SysDictData dict : datas) // for (SysDictData dict : datas)
{ // {
for (String label : dictLabel.split(separator)) // for (String label : dictLabel.split(separator))
{ // {
if (label.equals(dict.getDictLabel())) // if (label.equals(dict.getDictLabel()))
{ // {
propertyString.append(dict.getDictValue()).append(separator); // propertyString.append(dict.getDictValue()).append(separator);
break; // break;
} // }
} // }
} // }
} // }
else // else
{ // {
for (SysDictData dict : datas) // for (SysDictData dict : datas)
{ // {
if (dictLabel.equals(dict.getDictLabel())) // if (dictLabel.equals(dict.getDictLabel()))
{ // {
return dict.getDictValue(); // return dict.getDictValue();
} // }
} // }
} // }
return StringUtils.stripEnd(propertyString.toString(), separator); // return StringUtils.stripEnd(propertyString.toString(), separator);
} // }
//
/** // /**
* 删除指定字典缓存 // * 删除指定字典缓存
* // *
* @param key 字典键 // * @param key 字典键
*/ // */
public static void removeDictCache(String key) // public static void removeDictCache(String key)
{ // {
SpringUtils.getBean(RedisCache.class).deleteObject(getCacheKey(key)); // SpringUtils.getBean(RedisCache.class).deleteObject(getCacheKey(key));
} // }
//
/** // /**
* 清空字典缓存 // * 清空字典缓存
*/ // */
public static void clearDictCache() // public static void clearDictCache()
{ // {
Collection<String> keys = SpringUtils.getBean(RedisCache.class).keys(CacheConstants.SYS_DICT_KEY + "*"); // Collection<String> keys = SpringUtils.getBean(RedisCache.class).keys(CacheConstants.SYS_DICT_KEY + "*");
SpringUtils.getBean(RedisCache.class).deleteObject(keys); // SpringUtils.getBean(RedisCache.class).deleteObject(keys);
} // }
//
/** // /**
* 设置cache key // * 设置cache key
* // *
* @param configKey 参数键 // * @param configKey 参数键
* @return 缓存键key // * @return 缓存键key
*/ // */
public static String getCacheKey(String configKey) // public static String getCacheKey(String configKey)
{ // {
return CacheConstants.SYS_DICT_KEY + configKey; // return CacheConstants.SYS_DICT_KEY + configKey;
} // }
} //}

View File

@ -0,0 +1,119 @@
package cn.qihangerp.sys.controller;
import cn.qihangerp.common.AjaxResult;
import cn.qihangerp.common.constant.UserConstants;
import cn.qihangerp.common.utils.StringUtils;
import cn.qihangerp.module.domain.SysDept;
import cn.qihangerp.module.service.ISysDeptService;
import cn.qihangerp.security.common.BaseController;
import org.apache.commons.lang3.ArrayUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* 部门信息
*
* @author qihang
*/
@RestController
@RequestMapping("/system/dept")
public class SysDeptController extends BaseController
{
@Autowired
private ISysDeptService deptService;
/**
* 获取部门列表
*/
@PreAuthorize("@ss.hasPermi('system:dept:list')")
@GetMapping("/list")
public AjaxResult list(SysDept dept)
{
List<SysDept> depts = deptService.selectDeptList(dept);
return success(depts);
}
/**
* 查询部门列表排除节点
*/
@PreAuthorize("@ss.hasPermi('system:dept:list')")
@GetMapping("/list/exclude/{deptId}")
public AjaxResult excludeChild(@PathVariable(value = "deptId", required = false) Long deptId)
{
List<SysDept> depts = deptService.selectDeptList(new SysDept());
depts.removeIf(d -> d.getDeptId().intValue() == deptId || ArrayUtils.contains(StringUtils.split(d.getAncestors(), ","), deptId + ""));
return success(depts);
}
/**
* 根据部门编号获取详细信息
*/
@PreAuthorize("@ss.hasPermi('system:dept:query')")
@GetMapping(value = "/{deptId}")
public AjaxResult getInfo(@PathVariable Long deptId)
{
deptService.checkDeptDataScope(deptId,getUserId());
return success(deptService.selectDeptById(deptId));
}
/**
* 新增部门
*/
@PostMapping
public AjaxResult add(@Validated @RequestBody SysDept dept)
{
if (!deptService.checkDeptNameUnique(dept))
{
return error("新增部门'" + dept.getDeptName() + "'失败,部门名称已存在");
}
dept.setCreateBy(getUsername());
return toAjax(deptService.insertDept(dept));
}
/**
* 修改部门
*/
@PutMapping
public AjaxResult edit(@Validated @RequestBody SysDept dept)
{
Long deptId = dept.getDeptId();
deptService.checkDeptDataScope(deptId,getUserId());
if (!deptService.checkDeptNameUnique(dept))
{
return error("修改部门'" + dept.getDeptName() + "'失败,部门名称已存在");
}
else if (dept.getParentId().equals(deptId))
{
return error("修改部门'" + dept.getDeptName() + "'失败,上级部门不能是自己");
}
else if (StringUtils.equals(UserConstants.DEPT_DISABLE, dept.getStatus()) && deptService.selectNormalChildrenDeptById(deptId) > 0)
{
return error("该部门包含未停用的子部门!");
}
dept.setUpdateBy(getUsername());
return toAjax(deptService.updateDept(dept));
}
/**
* 删除部门
*/
@DeleteMapping("/{deptId}")
public AjaxResult remove(@PathVariable Long deptId)
{
if (deptService.hasChildByDeptId(deptId))
{
return warn("存在下级部门,不允许删除");
}
if (deptService.checkDeptExistUser(deptId))
{
return warn("部门存在用户,不允许删除");
}
deptService.checkDeptDataScope(deptId,getUserId());
return toAjax(deptService.deleteDeptById(deptId));
}
}

View File

@ -0,0 +1,218 @@
package cn.qihangerp.sys.controller;
import cn.qihangerp.common.AjaxResult;
import cn.qihangerp.common.TableDataInfo;
import cn.qihangerp.common.utils.StringUtils;
import cn.qihangerp.domain.SysRole;
import cn.qihangerp.domain.SysUser;
import cn.qihangerp.module.domain.SysDept;
import cn.qihangerp.module.domain.SysUserRole;
import cn.qihangerp.module.service.ISysDeptService;
import cn.qihangerp.module.service.ISysRoleService;
import cn.qihangerp.module.service.SysPermissionService;
import cn.qihangerp.security.LoginUser;
import cn.qihangerp.security.TokenService;
import cn.qihangerp.security.common.BaseController;
import cn.qihangerp.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* 角色信息
*
* @author qihang
*/
@RestController
@RequestMapping("/system/role")
public class SysRoleController extends BaseController
{
@Autowired
private ISysRoleService roleService;
@Autowired
private TokenService tokenService;
@Autowired
private SysPermissionService permissionService;
@Autowired
private ISysUserService userService;
@Autowired
private ISysDeptService deptService;
@PreAuthorize("@ss.hasPermi('system:role:list')")
@GetMapping("/list")
public TableDataInfo list(SysRole role)
{
// startPage(false);
List<SysRole> list = roleService.selectRoleList(role);
return getDataTable(list);
}
/**
* 根据角色编号获取详细信息
*/
@GetMapping(value = "/{roleId}")
public AjaxResult getInfo(@PathVariable Long roleId)
{
roleService.checkRoleDataScope(roleId,getUserId());
return success(roleService.selectRoleById(roleId));
}
/**
* 新增角色
*/
@PostMapping
public AjaxResult add(@Validated @RequestBody SysRole role)
{
if (!roleService.checkRoleNameUnique(role))
{
return error("新增角色'" + role.getRoleName() + "'失败,角色名称已存在");
}
else if (!roleService.checkRoleKeyUnique(role))
{
return error("新增角色'" + role.getRoleName() + "'失败,角色权限已存在");
}
role.setCreateBy(getUsername());
return toAjax(roleService.insertRole(role));
}
/**
* 修改保存角色
*/
@PutMapping
public AjaxResult edit(@Validated @RequestBody SysRole role)
{
roleService.checkRoleAllowed(role);
roleService.checkRoleDataScope(role.getRoleId(),getUserId());
if (!roleService.checkRoleNameUnique(role))
{
return error("修改角色'" + role.getRoleName() + "'失败,角色名称已存在");
}
else if (!roleService.checkRoleKeyUnique(role))
{
return error("修改角色'" + role.getRoleName() + "'失败,角色权限已存在");
}
role.setUpdateBy(getUsername());
if (roleService.updateRole(role) > 0)
{
// 更新缓存用户权限
LoginUser loginUser = getLoginUser();
if (StringUtils.isNotNull(loginUser.getUser()) && !loginUser.getUser().isAdmin())
{
loginUser.setPermissions(permissionService.getMenuPermission(loginUser.getUser()));
loginUser.setUser(userService.selectUserByUserName(loginUser.getUser().getUserName()));
tokenService.setLoginUser(loginUser);
}
return success();
}
return error("修改角色'" + role.getRoleName() + "'失败,请联系管理员");
}
/**
* 状态修改
*/
@PutMapping("/changeStatus")
public AjaxResult changeStatus(@RequestBody SysRole role)
{
roleService.checkRoleAllowed(role);
roleService.checkRoleDataScope(role.getRoleId(),getUserId());
role.setUpdateBy(getUsername());
return toAjax(roleService.updateRoleStatus(role));
}
/**
* 删除角色
*/
@DeleteMapping("/{roleIds}")
public AjaxResult remove(@PathVariable Long[] roleIds)
{
return toAjax(roleService.deleteRoleByIds(roleIds,getUserId()));
}
/**
* 获取角色选择框列表
*/
@PreAuthorize("@ss.hasPermi('system:role:query')")
@GetMapping("/optionselect")
public AjaxResult optionselect()
{
return success(roleService.selectRoleAll());
}
/**
* 查询已分配用户角色列表
*/
@PreAuthorize("@ss.hasPermi('system:role:list')")
@GetMapping("/authUser/allocatedList")
public TableDataInfo allocatedList(SysUser user)
{
// startPage();
List<SysUser> list = userService.selectAllocatedList(user);
return getDataTable(list);
}
/**
* 查询未分配用户角色列表
*/
@PreAuthorize("@ss.hasPermi('system:role:list')")
@GetMapping("/authUser/unallocatedList")
public TableDataInfo unallocatedList(SysUser user)
{
// startPage();
List<SysUser> list = userService.selectUnallocatedList(user);
return getDataTable(list);
}
/**
* 取消授权用户
*/
@PutMapping("/authUser/cancel")
public AjaxResult cancelAuthUser(@RequestBody SysUserRole userRole)
{
return toAjax(roleService.deleteAuthUser(userRole));
}
/**
* 批量取消授权用户
*/
@PutMapping("/authUser/cancelAll")
public AjaxResult cancelAuthUserAll(Long roleId, Long[] userIds)
{
return toAjax(roleService.deleteAuthUsers(roleId, userIds));
}
/**
* 批量选择用户授权
*/
@PutMapping("/authUser/selectAll")
public AjaxResult selectAuthUserAll(Long roleId, Long[] userIds)
{
roleService.checkRoleDataScope(roleId,getUserId());
return toAjax(roleService.insertAuthUsers(roleId, userIds));
}
/**
* 获取对应角色部门树列表
*/
@PreAuthorize("@ss.hasPermi('system:role:query')")
@GetMapping(value = "/deptTree/{roleId}")
public AjaxResult deptTree(@PathVariable("roleId") Long roleId)
{
AjaxResult ajax = AjaxResult.success();
ajax.put("checkedKeys", deptService.selectDeptListByRoleId(roleId));
ajax.put("depts", deptService.selectDeptTreeList(new SysDept()));
return ajax;
}
}