当前位置:   article > 正文

基于springboot实现功能超全企业进销存系统_基于springboot的企业商品进销管理系统翻译

基于springboot的企业商品进销管理系统翻译

作者主页:编程指南针

作者简介:Java领域优质创作者、CSDN博客专家 、掘金特邀作者、多年架构师设计经验、腾讯课堂常驻讲师

主要内容:Java项目、毕业设计、简历模板、学习资料、面试题库、技术互助

收藏点赞不迷路  关注作者有好处

文末获取源码 

项目编号:BS-XX-099

后台开发:Springboot+mybatis+springmvc

前台开发:bootstrap+easyui+jquery+highcharts

数据库:MYSQL

开发工具:IDEA / ECLIPSE

应用服务器:TOMCAT8.5

本系统基于springboot实现了一个功能十分完整的企业进销存系统,主要功能包括:用户的登录注册、客户信息增添改查、来往客户信息查询等、商品的进货和销售、采购订单明细、销售订单明细、库存盘点、商品查询及分类、商品价格调整、进销存报表、商品库存预警、系统退出、角色管理、用户管理、权限分配、数据统计图形报表、等等,功能可以说是十分完整,整个系统设计简洁大方,运行无误。

下面展示一下系统的主要功能:

登陆页面:

管理主页面

系统管理-角色管理

系统管理-用户管理

基础资料-供应商管理

基础资料-客户管理

基础资料-商品分类和商品管理

基础资料-期初库存管理

统计报表—供应商统计

统计报表—按日统计

库存管理-商品报损

库存管理-库存报警

销售管理—销售出货

销售管理—销售单据查询

进货管理—进货入库

进货管理—进货单据查询

进货管理—退货出库

篇幅所限,只展示部分功能,整体来说,此系统还是十分优秀,包含了进销存常见所有的功能需求。

部分核心实现代码:

  1. package com.jude.controller.admin;
  2. import com.jude.service.LogService;
  3. import com.jude.entity.Customer;
  4. import com.jude.entity.Log;
  5. import com.jude.service.CustomerService;
  6. import org.apache.shiro.authz.annotation.Logical;
  7. import org.apache.shiro.authz.annotation.RequiresPermissions;
  8. import org.springframework.data.domain.Sort.Direction;
  9. import org.springframework.web.bind.annotation.RequestMapping;
  10. import org.springframework.web.bind.annotation.RequestParam;
  11. import org.springframework.web.bind.annotation.ResponseBody;
  12. import org.springframework.web.bind.annotation.RestController;
  13. import javax.annotation.Resource;
  14. import java.util.HashMap;
  15. import java.util.List;
  16. import java.util.Map;
  17. /**
  18. * 后台管理客户Controller
  19. * @author znz
  20. *
  21. */
  22. @RestController
  23. @RequestMapping("/admin/customer")
  24. public class CustomerAdminController {
  25. @Resource
  26. private CustomerService customerService;
  27. @Resource
  28. private LogService logService;
  29. /**
  30. * 分页查询客户信息
  31. * @param customer
  32. * @param page
  33. * @param rows
  34. * @return
  35. * @throws Exception
  36. */
  37. @RequestMapping("/list")
  38. @RequiresPermissions(value = { "客户管理" })
  39. public Map<String,Object> list(Customer customer, @RequestParam(value="page",required=false)Integer page, @RequestParam(value="rows",required=false)Integer rows)throws Exception{
  40. List<Customer> customerList=customerService.list(customer, page, rows, Direction.ASC, "id");
  41. Long total=customerService.getCount(customer);
  42. Map<String, Object> resultMap = new HashMap<>();
  43. resultMap.put("rows", customerList);
  44. resultMap.put("total", total);
  45. logService.save(new Log(Log.SEARCH_ACTION,"查询客户信息")); // 写入日志
  46. return resultMap;
  47. }
  48. /**
  49. * 下拉框模糊查询
  50. * @param q
  51. * @return
  52. * @throws Exception
  53. */
  54. @ResponseBody
  55. @RequestMapping("/comboList")
  56. @RequiresPermissions(value = {"销售出库","客户退货","销售单据查询","客户退货查询"},logical=Logical.OR)
  57. public List<Customer> comboList(String q)throws Exception{
  58. if(q==null){
  59. q="";
  60. }
  61. return customerService.findByName("%"+q+"%");
  62. }
  63. /**
  64. * 添加或者修改客户信息
  65. * @param customer
  66. * @return
  67. * @throws Exception
  68. */
  69. @RequestMapping("/save")
  70. @RequiresPermissions(value = { "客户管理" })
  71. public Map<String,Object> save(Customer customer)throws Exception{
  72. if(customer.getId()!=null){ // 写入日志
  73. logService.save(new Log(Log.UPDATE_ACTION,"更新客户信息"+customer));
  74. }else{
  75. logService.save(new Log(Log.ADD_ACTION,"添加客户信息"+customer));
  76. }
  77. Map<String, Object> resultMap = new HashMap<>();
  78. customerService.save(customer);
  79. resultMap.put("success", true);
  80. return resultMap;
  81. }
  82. /**
  83. * 删除客户信息
  84. * @param id
  85. * @param response
  86. * @return
  87. * @throws Exception
  88. */
  89. @RequestMapping("/delete")
  90. @RequiresPermissions(value = { "客户管理" })
  91. public Map<String,Object> delete(String ids)throws Exception{
  92. Map<String, Object> resultMap = new HashMap<>();
  93. String []idsStr=ids.split(",");
  94. for(int i=0;i<idsStr.length;i++){
  95. int id=Integer.parseInt(idsStr[i]);
  96. logService.save(new Log(Log.DELETE_ACTION,"删除客户信息"+customerService.findById(id))); // 写入日志
  97. customerService.delete(id);
  98. }
  99. resultMap.put("success", true);
  100. return resultMap;
  101. }
  102. }

  1. package com.jude.controller.admin;
  2. import com.google.gson.Gson;
  3. import com.google.gson.reflect.TypeToken;
  4. import com.jude.service.CustomerReturnListGoodsService;
  5. import com.jude.service.CustomerReturnListService;
  6. import com.jude.service.LogService;
  7. import com.jude.util.DateUtil;
  8. import com.jude.util.StringUtil;
  9. import com.jude.entity.CustomerReturnList;
  10. import com.jude.entity.CustomerReturnListGoods;
  11. import com.jude.entity.Log;
  12. import com.jude.service.UserService;
  13. import org.apache.shiro.SecurityUtils;
  14. import org.apache.shiro.authz.annotation.RequiresPermissions;
  15. import org.springframework.beans.propertyeditors.CustomDateEditor;
  16. import org.springframework.data.domain.Sort.Direction;
  17. import org.springframework.web.bind.WebDataBinder;
  18. import org.springframework.web.bind.annotation.InitBinder;
  19. import org.springframework.web.bind.annotation.RequestMapping;
  20. import org.springframework.web.bind.annotation.ResponseBody;
  21. import org.springframework.web.bind.annotation.RestController;
  22. import javax.annotation.Resource;
  23. import java.text.SimpleDateFormat;
  24. import java.util.Date;
  25. import java.util.HashMap;
  26. import java.util.List;
  27. import java.util.Map;
  28. /**
  29. * 客户退货单Controller类
  30. * @author Administrator
  31. *
  32. */
  33. @RestController
  34. @RequestMapping("/admin/customerReturnList")
  35. public class CustomerReturnListAdminController {
  36. @Resource
  37. private CustomerReturnListService customerReturnListService;
  38. @Resource
  39. private CustomerReturnListGoodsService customerReturnListGoodsService;
  40. @Resource
  41. private LogService logService;
  42. @Resource
  43. private UserService userService;
  44. @InitBinder
  45. public void initBinder(WebDataBinder binder) {
  46. SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
  47. dateFormat.setLenient(true);
  48. binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true)); //true:允许输入空值,false:不能为空值
  49. }
  50. /**
  51. * 根据条件分页查询客户退货单信息
  52. * @param customerReturnList
  53. * @param page
  54. * @param rows
  55. * @return
  56. * @throws Exception
  57. */
  58. @RequestMapping("/list")
  59. @RequiresPermissions(value = { "客户退货查询" })
  60. public Map<String,Object> list(CustomerReturnList customerReturnList)throws Exception{
  61. Map<String, Object> resultMap = new HashMap<>();
  62. List<CustomerReturnList> customerReturnListList=customerReturnListService.list(customerReturnList, Direction.DESC, "customerReturnDate");
  63. resultMap.put("rows", customerReturnListList);
  64. return resultMap;
  65. }
  66. /**
  67. * 根据客户退货单id查询所有客户退货单商品
  68. * @param customerReturnListId
  69. * @return
  70. * @throws Exception
  71. */
  72. @RequestMapping("/listGoods")
  73. @RequiresPermissions(value = { "客户退货查询" })
  74. public Map<String,Object> listGoods(Integer customerReturnListId)throws Exception{
  75. if(customerReturnListId==null){
  76. return null;
  77. }
  78. Map<String, Object> resultMap = new HashMap<>();
  79. List<CustomerReturnListGoods> customerReturnListGoodsList=customerReturnListGoodsService.listByCustomerReturnListId(customerReturnListId);
  80. resultMap.put("rows", customerReturnListGoodsList);
  81. return resultMap;
  82. }
  83. /**
  84. * 客户统计 获取客户退货单的所有商品信息
  85. * @param purchaseList
  86. * @param purchaseListGoods
  87. * @return
  88. * @throws Exception
  89. */
  90. @RequestMapping("/listCount")
  91. @RequiresPermissions(value = { "客户统计" })
  92. public Map<String,Object> listCount(CustomerReturnList customerReturnList,CustomerReturnListGoods customerReturnListGoods)throws Exception{
  93. Map<String, Object> resultMap = new HashMap<>();
  94. List<CustomerReturnList> customerReturnListList=customerReturnListService.list(customerReturnList, Direction.DESC, "customerReturnDate");
  95. for(CustomerReturnList crl:customerReturnListList){
  96. customerReturnListGoods.setCustomerReturnList(crl);
  97. List<CustomerReturnListGoods> crlList=customerReturnListGoodsService.list(customerReturnListGoods);
  98. for(CustomerReturnListGoods crlg:crlList){
  99. crlg.setCustomerReturnList(null);
  100. }
  101. crl.setCustomerReturnListGoodsList(crlList);
  102. }
  103. resultMap.put("rows", customerReturnListList);
  104. return resultMap;
  105. }
  106. /**
  107. * 获取客户退货单号
  108. * @param type
  109. * @return
  110. * @throws Exception
  111. */
  112. @ResponseBody
  113. @RequestMapping("/getCustomerReturnNumber")
  114. @RequiresPermissions(value = {"客户退货"})
  115. public String genBillCode(String type)throws Exception{
  116. StringBuffer biilCodeStr=new StringBuffer();
  117. biilCodeStr.append("XT");
  118. biilCodeStr.append(DateUtil.getCurrentDateStr()); // 拼接当前日期
  119. String customerReturnNumber=customerReturnListService.getTodayMaxCustomerReturnNumber(); // 获取当天最大的客户退货单号
  120. if(customerReturnNumber!=null){
  121. biilCodeStr.append(StringUtil.formatCode(customerReturnNumber));
  122. }else{
  123. biilCodeStr.append("0001");
  124. }
  125. return biilCodeStr.toString();
  126. }
  127. /**
  128. * 添加客户退货单 以及所有客户退货单商品
  129. * @param customerReturnList
  130. * @param goodsJson
  131. * @return
  132. * @throws Exception
  133. */
  134. @ResponseBody
  135. @RequestMapping("/save")
  136. @RequiresPermissions(value = {"客户退货"})
  137. public Map<String,Object> save(CustomerReturnList customerReturnList,String goodsJson)throws Exception{
  138. Map<String, Object> resultMap = new HashMap<>();
  139. customerReturnList.setUser(userService.findByUserName((String) SecurityUtils.getSubject().getPrincipal())); // 设置操作用户
  140. Gson gson = new Gson();
  141. List<CustomerReturnListGoods> plgList=gson.fromJson(goodsJson, new TypeToken<List<CustomerReturnListGoods>>(){}.getType());
  142. customerReturnListService.save(customerReturnList, plgList);
  143. logService.save(new Log(Log.ADD_ACTION,"添加客户退货单"));
  144. resultMap.put("success", true);
  145. return resultMap;
  146. }
  147. /**
  148. * 修改退货单的支付状态
  149. * @param id
  150. * @return
  151. * @throws Exception
  152. */
  153. @ResponseBody
  154. @RequestMapping("/update")
  155. @RequiresPermissions(value = {"客户统计"})
  156. public Map<String,Object> update(Integer id)throws Exception{
  157. Map<String, Object> resultMap = new HashMap<>();
  158. CustomerReturnList customerReturnList=customerReturnListService.findById(id);
  159. customerReturnList.setState(1); // 修改成支付状态
  160. customerReturnListService.update(customerReturnList);
  161. resultMap.put("success", true);
  162. return resultMap;
  163. }
  164. /**
  165. * 根据id删除客户退货单信息 包括客户退货单里的商品
  166. * @param id
  167. * @return
  168. * @throws Exception
  169. */
  170. @RequestMapping("/delete")
  171. @RequiresPermissions(value = { "客户退货查询" })
  172. public Map<String,Object> delete(Integer id)throws Exception{
  173. Map<String, Object> resultMap = new HashMap<>();
  174. customerReturnListService.delete(id);
  175. logService.save(new Log(Log.DELETE_ACTION,"删除客户退货单信息"+customerReturnListService.findById(id))); // 写入日志
  176. resultMap.put("success", true);
  177. return resultMap;
  178. }
  179. }
  1. package com.jude.controller.admin;
  2. import com.google.gson.Gson;
  3. import com.google.gson.reflect.TypeToken;
  4. import com.jude.entity.PurchaseListGoods;
  5. import com.jude.service.LogService;
  6. import com.jude.util.StringUtil;
  7. import com.jude.entity.Log;
  8. import com.jude.entity.PurchaseList;
  9. import com.jude.service.PurchaseListGoodsService;
  10. import com.jude.service.PurchaseListService;
  11. import com.jude.service.UserService;
  12. import com.jude.util.DateUtil;
  13. import org.apache.shiro.SecurityUtils;
  14. import org.apache.shiro.authz.annotation.RequiresPermissions;
  15. import org.springframework.beans.propertyeditors.CustomDateEditor;
  16. import org.springframework.data.domain.Sort.Direction;
  17. import org.springframework.web.bind.WebDataBinder;
  18. import org.springframework.web.bind.annotation.InitBinder;
  19. import org.springframework.web.bind.annotation.RequestMapping;
  20. import org.springframework.web.bind.annotation.ResponseBody;
  21. import org.springframework.web.bind.annotation.RestController;
  22. import javax.annotation.Resource;
  23. import java.text.SimpleDateFormat;
  24. import java.util.Date;
  25. import java.util.HashMap;
  26. import java.util.List;
  27. import java.util.Map;
  28. /**
  29. * 进货单Controller类
  30. * @author Administrator
  31. *
  32. */
  33. @RestController
  34. @RequestMapping("/admin/purchaseList")
  35. public class PurchaseListAdminController {
  36. @Resource
  37. private PurchaseListService purchaseListService;
  38. @Resource
  39. private PurchaseListGoodsService purchaseListGoodsService;
  40. @Resource
  41. private LogService logService;
  42. @Resource
  43. private UserService userService;
  44. @InitBinder
  45. public void initBinder(WebDataBinder binder) {
  46. SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
  47. dateFormat.setLenient(true);
  48. binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true)); //true:允许输入空值,false:不能为空值
  49. }
  50. /**
  51. * 根据条件分页查询进货单信息
  52. * @param purchaseList
  53. * @param page
  54. * @param rows
  55. * @return
  56. * @throws Exception
  57. */
  58. @RequestMapping("/list")
  59. @RequiresPermissions(value = { "进货单据查询" })
  60. public Map<String,Object> list(PurchaseList purchaseList)throws Exception{
  61. Map<String, Object> resultMap = new HashMap<>();
  62. List<PurchaseList> purchaseListList=purchaseListService.list(purchaseList, Direction.DESC, "purchaseDate");
  63. resultMap.put("rows", purchaseListList);
  64. return resultMap;
  65. }
  66. /**
  67. * 根据进货单id查询所有进货单商品
  68. * @param purchaseListId
  69. * @return
  70. * @throws Exception
  71. */
  72. @RequestMapping("/listGoods")
  73. @RequiresPermissions(value = { "进货单据查询" })
  74. public Map<String,Object> listGoods(Integer purchaseListId)throws Exception{
  75. if(purchaseListId==null){
  76. return null;
  77. }
  78. Map<String, Object> resultMap = new HashMap<>();
  79. List<PurchaseListGoods> purchaseListGoodsList=purchaseListGoodsService.listByPurchaseListId(purchaseListId);
  80. resultMap.put("rows", purchaseListGoodsList);
  81. return resultMap;
  82. }
  83. /**
  84. * 客户统计 获取进货单的所有商品信息
  85. * @param purchaseList
  86. * @param purchaseListGoods
  87. * @return
  88. * @throws Exception
  89. */
  90. @RequestMapping("/listCount")
  91. @RequiresPermissions(value = { "客户统计" })
  92. public Map<String,Object> listCount(PurchaseList purchaseList,PurchaseListGoods purchaseListGoods)throws Exception{
  93. Map<String, Object> resultMap = new HashMap<>();
  94. List<PurchaseList> purchaseListList=purchaseListService.list(purchaseList, Direction.DESC, "purchaseDate");
  95. for(PurchaseList pl:purchaseListList){
  96. purchaseListGoods.setPurchaseList(pl);
  97. List<PurchaseListGoods> plgList=purchaseListGoodsService.list(purchaseListGoods);
  98. for(PurchaseListGoods plg:plgList){
  99. plg.setPurchaseList(null);
  100. }
  101. pl.setPurchaseListGoodsList(plgList);
  102. }
  103. resultMap.put("rows", purchaseListList);
  104. return resultMap;
  105. }
  106. /**
  107. * 获取进货单号
  108. * @param type
  109. * @return
  110. * @throws Exception
  111. */
  112. @ResponseBody
  113. @RequestMapping("/getPurchaseNumber")
  114. @RequiresPermissions(value = {"进货入库"})
  115. public String genBillCode(String type)throws Exception{
  116. StringBuffer biilCodeStr=new StringBuffer();
  117. biilCodeStr.append("JH");
  118. biilCodeStr.append(DateUtil.getCurrentDateStr()); // 拼接当前日期
  119. String purchaseNumber=purchaseListService.getTodayMaxPurchaseNumber(); // 获取当天最大的进货单号
  120. if(purchaseNumber!=null){
  121. biilCodeStr.append(StringUtil.formatCode(purchaseNumber));
  122. }else{
  123. biilCodeStr.append("0001");
  124. }
  125. return biilCodeStr.toString();
  126. }
  127. /**
  128. * 添加进货单 以及所有进货单商品 以及 修改商品的成本均价
  129. * @param purchaseList
  130. * @param goodsJson
  131. * @return
  132. * @throws Exception
  133. */
  134. @ResponseBody
  135. @RequestMapping("/save")
  136. @RequiresPermissions(value = {"进货入库"})
  137. public Map<String,Object> save(PurchaseList purchaseList,String goodsJson)throws Exception{
  138. Map<String, Object> resultMap = new HashMap<>();
  139. purchaseList.setUser(userService.findByUserName((String) SecurityUtils.getSubject().getPrincipal())); // 设置操作用户
  140. Gson gson = new Gson();
  141. List<PurchaseListGoods> plgList=gson.fromJson(goodsJson, new TypeToken<List<PurchaseListGoods>>(){}.getType());
  142. purchaseListService.save(purchaseList, plgList);
  143. logService.save(new Log(Log.ADD_ACTION,"添加进货单"));
  144. resultMap.put("success", true);
  145. return resultMap;
  146. }
  147. /**
  148. * 修改进货单的支付状态
  149. * @param id
  150. * @return
  151. * @throws Exception
  152. */
  153. @ResponseBody
  154. @RequestMapping("/update")
  155. @RequiresPermissions(value = {"供应商统计"})
  156. public Map<String,Object> update(Integer id)throws Exception{
  157. Map<String, Object> resultMap = new HashMap<>();
  158. PurchaseList purchaseList=purchaseListService.findById(id);
  159. purchaseList.setState(1); // 修改成支付状态
  160. purchaseListService.update(purchaseList);
  161. resultMap.put("success", true);
  162. return resultMap;
  163. }
  164. /**
  165. * 根据id删除进货单信息 包括进货单里的商品
  166. * @param id
  167. * @return
  168. * @throws Exception
  169. */
  170. @RequestMapping("/delete")
  171. @RequiresPermissions(value = { "进货单据查询" })
  172. public Map<String,Object> delete(Integer id)throws Exception{
  173. Map<String, Object> resultMap = new HashMap<>();
  174. purchaseListService.delete(id);
  175. logService.save(new Log(Log.DELETE_ACTION,"删除进货单信息"+purchaseListService.findById(id))); // 写入日志
  176. resultMap.put("success", true);
  177. return resultMap;
  178. }
  179. }

  1. package com.jude.controller.admin;
  2. import com.google.gson.JsonArray;
  3. import com.google.gson.JsonObject;
  4. import com.jude.entity.Log;
  5. import com.jude.entity.Menu;
  6. import com.jude.entity.Role;
  7. import com.jude.service.*;
  8. import com.jude.util.StringUtil;
  9. import com.jude.entity.RoleMenu;
  10. import org.apache.shiro.authz.annotation.RequiresPermissions;
  11. import org.springframework.data.domain.Sort.Direction;
  12. import org.springframework.web.bind.annotation.PostMapping;
  13. import org.springframework.web.bind.annotation.RequestMapping;
  14. import org.springframework.web.bind.annotation.RequestParam;
  15. import org.springframework.web.bind.annotation.RestController;
  16. import javax.annotation.Resource;
  17. import java.util.HashMap;
  18. import java.util.LinkedList;
  19. import java.util.List;
  20. import java.util.Map;
  21. /**
  22. * 后台管理角色Controller
  23. * @author znz
  24. *
  25. */
  26. @RestController
  27. @RequestMapping("/admin/role")
  28. public class RoleAdminController {
  29. @Resource
  30. private RoleService roleService;
  31. @Resource
  32. private UserRoleService userRoleService;
  33. @Resource
  34. private MenuService menuService;
  35. @Resource
  36. private RoleMenuService roleMenuService;
  37. @Resource
  38. private LogService logService;
  39. /**
  40. * 查询所有角色
  41. * @return
  42. * @throws Exception
  43. */
  44. @RequestMapping("/listAll")
  45. @RequiresPermissions(value = { "角色管理" })
  46. public Map<String,Object> listAll()throws Exception{
  47. Map<String, Object> resultMap = new HashMap<>();
  48. resultMap.put("rows", roleService.listAll());
  49. logService.save(new Log(Log.SEARCH_ACTION,"查询所有角色信息")); // 写入日志
  50. return resultMap;
  51. }
  52. /**
  53. * 分页查询角色信息
  54. * @param user
  55. * @param page
  56. * @param rows
  57. * @return
  58. * @throws Exception
  59. */
  60. @RequestMapping("/list")
  61. @RequiresPermissions(value = { "角色管理" })
  62. public Map<String,Object> list(Role role, @RequestParam(value="page",required=false)Integer page, @RequestParam(value="rows",required=false)Integer rows)throws Exception{
  63. List<Role> roleList=roleService.list(role, page, rows, Direction.ASC, "id");
  64. Long total=roleService.getCount(role);
  65. Map<String, Object> resultMap = new HashMap<>();
  66. resultMap.put("rows", roleList);
  67. resultMap.put("total", total);
  68. logService.save(new Log(Log.SEARCH_ACTION,"查询角色信息")); // 写入日志
  69. return resultMap;
  70. }
  71. /**
  72. * 添加或者修改角色信息
  73. * @param role
  74. * @return
  75. * @throws Exception
  76. */
  77. @RequestMapping("/save")
  78. @RequiresPermissions(value = { "角色管理" })
  79. public Map<String,Object> save(Role role)throws Exception{
  80. if(role.getId()!=null){ // 写入日志
  81. logService.save(new Log(Log.UPDATE_ACTION,"更新角色信息"+role));
  82. }else{
  83. logService.save(new Log(Log.ADD_ACTION,"添加角色信息"+role));
  84. }
  85. Map<String, Object> resultMap = new HashMap<>();
  86. roleService.save(role);
  87. resultMap.put("success", true);
  88. return resultMap;
  89. }
  90. /**
  91. * 删除角色信息
  92. * @param id
  93. * @param response
  94. * @return
  95. * @throws Exception
  96. */
  97. @RequestMapping("/delete")
  98. @RequiresPermissions(value = { "角色管理" })
  99. public Map<String,Object> delete(Integer id)throws Exception{
  100. logService.save(new Log(Log.DELETE_ACTION,"删除角色信息"+roleService.findById(id))); // 写入日志
  101. Map<String, Object> resultMap = new HashMap<>();
  102. userRoleService.deleteByRoleId(id); // 删除用户角色关联信息
  103. roleService.delete(id);
  104. resultMap.put("success", true);
  105. return resultMap;
  106. }
  107. /**
  108. * 根据父节点获取所有复选框权限菜单树
  109. * @param parentId
  110. * @param roleId
  111. * @return
  112. * @throws Exception
  113. */
  114. @PostMapping("/loadCheckMenuInfo")
  115. @RequiresPermissions(value = { "角色管理" })
  116. public String loadCheckMenuInfo(Integer parentId,Integer roleId)throws Exception{
  117. List<Menu> menuList=menuService.findByRoleId(roleId); // 根据角色查询所有权限菜单信息
  118. List<Integer> menuIdList=new LinkedList<Integer>();
  119. for(Menu menu:menuList){
  120. menuIdList.add(menu.getId());
  121. }
  122. return getAllCheckedMenuByParentId(parentId,menuIdList).toString();
  123. }
  124. /**
  125. * 根据父节点ID和权限菜单ID集合获取复选框菜单节点
  126. * @param parentId
  127. * @param menuIdList
  128. * @return
  129. */
  130. private JsonArray getAllCheckedMenuByParentId(Integer parentId,List<Integer> menuIdList){
  131. JsonArray jsonArray=this.getCheckedMenuByParentId(parentId, menuIdList);
  132. for(int i=0;i<jsonArray.size();i++){
  133. JsonObject jsonObject=(JsonObject) jsonArray.get(i);
  134. if("open".equals(jsonObject.get("state").getAsString())){
  135. continue;
  136. }else{
  137. jsonObject.add("children", getAllCheckedMenuByParentId(jsonObject.get("id").getAsInt(),menuIdList));
  138. }
  139. }
  140. return jsonArray;
  141. }
  142. /**
  143. * 根据父节点ID和权限菜单ID集合获取复选框菜单节点
  144. * @param parentId
  145. * @param menuIdList
  146. * @return
  147. */
  148. private JsonArray getCheckedMenuByParentId(Integer parentId,List<Integer> menuIdList){
  149. List<Menu> menuList=menuService.findByParentId(parentId);
  150. JsonArray jsonArray=new JsonArray();
  151. for(Menu menu:menuList){
  152. JsonObject jsonObject=new JsonObject();
  153. int menuId=menu.getId();
  154. jsonObject.addProperty("id", menuId); // 节点id
  155. jsonObject.addProperty("text", menu.getName()); // 节点名称
  156. if(menu.getState()==1){
  157. jsonObject.addProperty("state", "closed"); // 根节点
  158. }else{
  159. jsonObject.addProperty("state", "open"); // 叶子节点
  160. }
  161. if(menuIdList.contains(menuId)){
  162. jsonObject.addProperty("checked", true);
  163. }
  164. jsonObject.addProperty("iconCls", menu.getIcon());
  165. jsonArray.add(jsonObject);
  166. }
  167. return jsonArray;
  168. }
  169. /**
  170. * 保存角色权限设置
  171. * @param menuIds
  172. * @param roleId
  173. * @return
  174. * @throws Exception
  175. */
  176. @RequestMapping("/saveMenuSet")
  177. @RequiresPermissions(value = { "角色管理" })
  178. public Map<String,Object> saveMenuSet(String menuIds,Integer roleId)throws Exception{
  179. Map<String, Object> resultMap = new HashMap<>();
  180. roleMenuService.deleteByRoleId(roleId); // 根据角色id删除所有角色权限关联实体
  181. if(StringUtil.isNotEmpty(menuIds)){
  182. String idsStr[]=menuIds.split(",");
  183. for(int i=0;i<idsStr.length;i++){ // 然后添加所有角色权限关联实体
  184. RoleMenu roleMenu=new RoleMenu();
  185. roleMenu.setRole(roleService.findById(roleId));
  186. roleMenu.setMenu(menuService.findById(Integer.parseInt(idsStr[i])));
  187. roleMenuService.save(roleMenu);
  188. }
  189. }
  190. resultMap.put("success", true);
  191. logService.save(new Log(Log.ADD_ACTION,"保存角色权限设置")); // 写入日志
  192. return resultMap;
  193. }
  194. }

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号