diff --git a/api/oms-api/src/main/java/cn/qihangerp/oms/controller/ShopController.java b/api/oms-api/src/main/java/cn/qihangerp/oms/controller/ShopController.java index ac37c4ee..ae1cba00 100644 --- a/api/oms-api/src/main/java/cn/qihangerp/oms/controller/ShopController.java +++ b/api/oms-api/src/main/java/cn/qihangerp/oms/controller/ShopController.java @@ -40,7 +40,7 @@ public class ShopController extends BaseController { @GetMapping("/list") public TableDataInfo list(ShopBo shop) { - LambdaQueryWrapper qw = new LambdaQueryWrapper().eq(shop.getPlatform()!=null,OShop::getType,shop.getPlatform()); + LambdaQueryWrapper qw = new LambdaQueryWrapper().eq(shop.getType()!=null,OShop::getType,shop.getType()); List list = shopService.list(qw); return getDataTable(list); } diff --git a/api/oms-api/src/main/java/cn/qihangerp/oms/request/ShopBo.java b/api/oms-api/src/main/java/cn/qihangerp/oms/request/ShopBo.java index 7d37ed21..4bb01823 100644 --- a/api/oms-api/src/main/java/cn/qihangerp/oms/request/ShopBo.java +++ b/api/oms-api/src/main/java/cn/qihangerp/oms/request/ShopBo.java @@ -20,7 +20,7 @@ public class ShopBo implements Serializable { /** * 对应第三方平台Id */ - private Integer platform; + private Integer type; diff --git a/api/sys-api/src/main/java/cn/qihangerp/sys/common/DictUtils.java b/api/sys-api/src/main/java/cn/qihangerp/sys/common/DictUtils.java index aa416ead..f1cf6bcc 100644 --- a/api/sys-api/src/main/java/cn/qihangerp/sys/common/DictUtils.java +++ b/api/sys-api/src/main/java/cn/qihangerp/sys/common/DictUtils.java @@ -1,189 +1,189 @@ -package cn.qihangerp.sys.common; - -import cn.qihangerp.domain.SysDictData; -import com.alibaba.fastjson2.JSONArray; -import cn.qihangerp.common.config.RedisCache; -import cn.qihangerp.common.constant.CacheConstants; -import cn.qihangerp.common.utils.SpringUtils; -import cn.qihangerp.common.utils.StringUtils; - - -import java.util.Collection; -import java.util.List; - -/** - * 字典工具类 - * - * @author qihang - */ -public class DictUtils -{ - /** - * 分隔符 - */ - public static final String SEPARATOR = ","; - - /** - * 设置字典缓存 - * - * @param key 参数键 - * @param dictDatas 字典数据列表 - */ - public static void setDictCache(String key, List dictDatas) - { - SpringUtils.getBean(RedisCache.class).setCacheObject(getCacheKey(key), dictDatas); - } - - /** - * 获取字典缓存 - * - * @param key 参数键 - * @return dictDatas 字典数据列表 - */ - public static List getDictCache(String key) - { - JSONArray arrayCache = SpringUtils.getBean(RedisCache.class).getCacheObject(getCacheKey(key)); - if (StringUtils.isNotNull(arrayCache)) - { - return arrayCache.toList(SysDictData.class); - } - return null; - } - - /** - * 根据字典类型和字典值获取字典标签 - * - * @param dictType 字典类型 - * @param dictValue 字典值 - * @return 字典标签 - */ - public static String getDictLabel(String dictType, String dictValue) - { - return getDictLabel(dictType, dictValue, SEPARATOR); - } - - /** - * 根据字典类型和字典标签获取字典值 - * - * @param dictType 字典类型 - * @param dictLabel 字典标签 - * @return 字典值 - */ - public static String getDictValue(String dictType, String dictLabel) - { - return getDictValue(dictType, dictLabel, SEPARATOR); - } - - /** - * 根据字典类型和字典值获取字典标签 - * - * @param dictType 字典类型 - * @param dictValue 字典值 - * @param separator 分隔符 - * @return 字典标签 - */ - public static String getDictLabel(String dictType, String dictValue, String separator) - { - StringBuilder propertyString = new StringBuilder(); - List datas = getDictCache(dictType); - - if (StringUtils.isNotNull(datas)) - { - if (StringUtils.containsAny(separator, dictValue)) - { - for (SysDictData dict : datas) - { - for (String value : dictValue.split(separator)) - { - if (value.equals(dict.getDictValue())) - { - propertyString.append(dict.getDictLabel()).append(separator); - break; - } - } - } - } - else - { - for (SysDictData dict : datas) - { - if (dictValue.equals(dict.getDictValue())) - { - return dict.getDictLabel(); - } - } - } - } - return StringUtils.stripEnd(propertyString.toString(), separator); - } - - /** - * 根据字典类型和字典标签获取字典值 - * - * @param dictType 字典类型 - * @param dictLabel 字典标签 - * @param separator 分隔符 - * @return 字典值 - */ - public static String getDictValue(String dictType, String dictLabel, String separator) - { - StringBuilder propertyString = new StringBuilder(); - List datas = getDictCache(dictType); - - if (StringUtils.containsAny(separator, dictLabel) && StringUtils.isNotEmpty(datas)) - { - for (SysDictData dict : datas) - { - for (String label : dictLabel.split(separator)) - { - if (label.equals(dict.getDictLabel())) - { - propertyString.append(dict.getDictValue()).append(separator); - break; - } - } - } - } - else - { - for (SysDictData dict : datas) - { - if (dictLabel.equals(dict.getDictLabel())) - { - return dict.getDictValue(); - } - } - } - return StringUtils.stripEnd(propertyString.toString(), separator); - } - - /** - * 删除指定字典缓存 - * - * @param key 字典键 - */ - public static void removeDictCache(String key) - { - SpringUtils.getBean(RedisCache.class).deleteObject(getCacheKey(key)); - } - - /** - * 清空字典缓存 - */ - public static void clearDictCache() - { - Collection keys = SpringUtils.getBean(RedisCache.class).keys(CacheConstants.SYS_DICT_KEY + "*"); - SpringUtils.getBean(RedisCache.class).deleteObject(keys); - } - - /** - * 设置cache key - * - * @param configKey 参数键 - * @return 缓存键key - */ - public static String getCacheKey(String configKey) - { - return CacheConstants.SYS_DICT_KEY + configKey; - } -} +//package cn.qihangerp.sys.common; +// +//import cn.qihangerp.domain.SysDictData; +//import com.alibaba.fastjson2.JSONArray; +//import cn.qihangerp.common.config.RedisCache; +//import cn.qihangerp.common.constant.CacheConstants; +//import cn.qihangerp.common.utils.SpringUtils; +//import cn.qihangerp.common.utils.StringUtils; +// +// +//import java.util.Collection; +//import java.util.List; +// +///** +// * 字典工具类 +// * +// * @author qihang +// */ +//public class DictUtils +//{ +// /** +// * 分隔符 +// */ +// public static final String SEPARATOR = ","; +// +// /** +// * 设置字典缓存 +// * +// * @param key 参数键 +// * @param dictDatas 字典数据列表 +// */ +// public static void setDictCache(String key, List dictDatas) +// { +// SpringUtils.getBean(RedisCache.class).setCacheObject(getCacheKey(key), dictDatas); +// } +// +// /** +// * 获取字典缓存 +// * +// * @param key 参数键 +// * @return dictDatas 字典数据列表 +// */ +// public static List getDictCache(String key) +// { +// JSONArray arrayCache = SpringUtils.getBean(RedisCache.class).getCacheObject(getCacheKey(key)); +// if (StringUtils.isNotNull(arrayCache)) +// { +// return arrayCache.toList(SysDictData.class); +// } +// return null; +// } +// +// /** +// * 根据字典类型和字典值获取字典标签 +// * +// * @param dictType 字典类型 +// * @param dictValue 字典值 +// * @return 字典标签 +// */ +// public static String getDictLabel(String dictType, String dictValue) +// { +// return getDictLabel(dictType, dictValue, SEPARATOR); +// } +// +// /** +// * 根据字典类型和字典标签获取字典值 +// * +// * @param dictType 字典类型 +// * @param dictLabel 字典标签 +// * @return 字典值 +// */ +// public static String getDictValue(String dictType, String dictLabel) +// { +// return getDictValue(dictType, dictLabel, SEPARATOR); +// } +// +// /** +// * 根据字典类型和字典值获取字典标签 +// * +// * @param dictType 字典类型 +// * @param dictValue 字典值 +// * @param separator 分隔符 +// * @return 字典标签 +// */ +// public static String getDictLabel(String dictType, String dictValue, String separator) +// { +// StringBuilder propertyString = new StringBuilder(); +// List datas = getDictCache(dictType); +// +// if (StringUtils.isNotNull(datas)) +// { +// if (StringUtils.containsAny(separator, dictValue)) +// { +// for (SysDictData dict : datas) +// { +// for (String value : dictValue.split(separator)) +// { +// if (value.equals(dict.getDictValue())) +// { +// propertyString.append(dict.getDictLabel()).append(separator); +// break; +// } +// } +// } +// } +// else +// { +// for (SysDictData dict : datas) +// { +// if (dictValue.equals(dict.getDictValue())) +// { +// return dict.getDictLabel(); +// } +// } +// } +// } +// return StringUtils.stripEnd(propertyString.toString(), separator); +// } +// +// /** +// * 根据字典类型和字典标签获取字典值 +// * +// * @param dictType 字典类型 +// * @param dictLabel 字典标签 +// * @param separator 分隔符 +// * @return 字典值 +// */ +// public static String getDictValue(String dictType, String dictLabel, String separator) +// { +// StringBuilder propertyString = new StringBuilder(); +// List datas = getDictCache(dictType); +// +// if (StringUtils.containsAny(separator, dictLabel) && StringUtils.isNotEmpty(datas)) +// { +// for (SysDictData dict : datas) +// { +// for (String label : dictLabel.split(separator)) +// { +// if (label.equals(dict.getDictLabel())) +// { +// propertyString.append(dict.getDictValue()).append(separator); +// break; +// } +// } +// } +// } +// else +// { +// for (SysDictData dict : datas) +// { +// if (dictLabel.equals(dict.getDictLabel())) +// { +// return dict.getDictValue(); +// } +// } +// } +// return StringUtils.stripEnd(propertyString.toString(), separator); +// } +// +// /** +// * 删除指定字典缓存 +// * +// * @param key 字典键 +// */ +// public static void removeDictCache(String key) +// { +// SpringUtils.getBean(RedisCache.class).deleteObject(getCacheKey(key)); +// } +// +// /** +// * 清空字典缓存 +// */ +// public static void clearDictCache() +// { +// Collection keys = SpringUtils.getBean(RedisCache.class).keys(CacheConstants.SYS_DICT_KEY + "*"); +// SpringUtils.getBean(RedisCache.class).deleteObject(keys); +// } +// +// /** +// * 设置cache key +// * +// * @param configKey 参数键 +// * @return 缓存键key +// */ +// public static String getCacheKey(String configKey) +// { +// return CacheConstants.SYS_DICT_KEY + configKey; +// } +//} diff --git a/api/sys-api/src/main/java/cn/qihangerp/sys/controller/SysDeptController.java b/api/sys-api/src/main/java/cn/qihangerp/sys/controller/SysDeptController.java new file mode 100644 index 00000000..107f0321 --- /dev/null +++ b/api/sys-api/src/main/java/cn/qihangerp/sys/controller/SysDeptController.java @@ -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 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 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)); + } +} diff --git a/api/sys-api/src/main/java/cn/qihangerp/sys/controller/SysRoleController.java b/api/sys-api/src/main/java/cn/qihangerp/sys/controller/SysRoleController.java new file mode 100644 index 00000000..611b9850 --- /dev/null +++ b/api/sys-api/src/main/java/cn/qihangerp/sys/controller/SysRoleController.java @@ -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 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 list = userService.selectAllocatedList(user); + return getDataTable(list); + } + + /** + * 查询未分配用户角色列表 + */ + @PreAuthorize("@ss.hasPermi('system:role:list')") + @GetMapping("/authUser/unallocatedList") + public TableDataInfo unallocatedList(SysUser user) + { +// startPage(); + List 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; + } +}