当前位置:   article > 正文

Java项目:校园物流快递管理系统(java+maven+JSP+SpringBoot+layui+mysql)_java校园流项目

java校园流项目

源码获取:博客首页 "资源" 里下载!

一、项目运行

环境配置:

Jdk1.8 + Tomcat8.5 + mysql + Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)

项目技术:

JSP +SpringBoot + MyBatis + html+ css + JavaScript + JQuery + Ajax + layui+ maven等等。


 

 

 

 

 

 

客户管理控制层:

  1. @Controller
  2. @RequestMapping("/customer")
  3. public class CustomerController {
  4. @Autowired
  5. private CustomerViewService customerViewService;
  6. @Autowired
  7. private CustomerService customerService;
  8. @Autowired
  9. private BasicDataService basicDataService;
  10. @Autowired
  11. private UserService userService;
  12. @RequestMapping("/list")
  13. @RequiresPermissions("customer:list")
  14. public String list() {
  15. return "customer/list";
  16. }
  17. @ResponseBody
  18. @RequestMapping("/getCustomers")
  19. @RequiresPermissions("customer:list")
  20. public PageInfo<CustomerView> getCustomers(String keyWord,
  21. @RequestParam(defaultValue = "1") Integer pageNum,
  22. @RequestParam(defaultValue = "10") Integer pageSize) {
  23. //开始分页,这里启动并设置页码,和每页结果数量后,后续结果会自动为分页后结果
  24. PageHelper.startPage(pageNum, pageSize);
  25. CustomerViewExample customerViewExample = new CustomerViewExample();
  26. CustomerViewExample.Criteria criteria = customerViewExample.createCriteria();
  27. /**
  28. * StringUtils.isNotBlank 可以判断 ""/" "/nullfalse
  29. */
  30. if (StringUtils.isNotBlank(keyWord)) {
  31. //权限名条件
  32. criteria.andCustomerNameLike("%" + keyWord + "%");
  33. }
  34. //判断当前登录用户是否为业务员,业务员只能查看自己的客户
  35. Subject subject = SecurityUtils.getSubject();
  36. User user = (User) subject.getPrincipal();
  37. if (user.getRoleId() == ConstantDataField.SALESMAN_ROLE_ID) {
  38. //客户的业务员id等于登录用户的id
  39. criteria.andUserIdEqualTo(user.getUserId());
  40. }
  41. List<CustomerView> customers = customerViewService.selectByExample(customerViewExample);
  42. //获得分页对象
  43. PageInfo<CustomerView> pageInfo = new PageInfo<>(customers);
  44. return pageInfo;
  45. }
  46. @ResponseBody
  47. @RequestMapping("/delete")
  48. @RequiresPermissions("customer:delete")
  49. public Map<String, String> delete(Long[] customerIds) {
  50. HashMap<String, String> map = new HashMap<>();
  51. if (customerIds.length == 1) {
  52. int res = customerService.deleteByPrimaryKey(customerIds[0]);
  53. if (res == 1) {
  54. map.put("status", "true");
  55. map.put("info", "删除成功!");
  56. return map;
  57. }
  58. map.put("status", "false");
  59. map.put("info", "删除失败!客户已经不存在");
  60. return map;
  61. }
  62. //批量删除
  63. int success = 0;
  64. int total = customerIds.length;
  65. for(Long customerId : customerIds) {
  66. success += customerService.deleteByPrimaryKey(customerId);
  67. }
  68. map.put("status", "true");
  69. map.put("info", "成功删除选中 " + total + " 个客户中的 " + success + " 个客户");
  70. return map;
  71. }
  72. @RequestMapping("/add")
  73. @RequiresPermissions("customer:insert")
  74. public String add(Model m) {
  75. //查出地区列表
  76. BasicDataExample basicDataExample = new BasicDataExample();
  77. basicDataExample.createCriteria().andParentIdEqualTo(ConstantDataField.AREA_BASICDATA_ID);
  78. List<BasicData> basicDatas= basicDataService.selectByExample(basicDataExample);
  79. m.addAttribute("areas",basicDatas);
  80. //获取当前登录用户
  81. Subject subject = SecurityUtils.getSubject();
  82. User user = (User) subject.getPrincipal();
  83. //如果是业务员进行操作,只能选择自己作为业务员
  84. List<User> users = new ArrayList<>();
  85. if (user.getRoleId() == ConstantDataField.SALESMAN_ROLE_ID) {
  86. users.add(user);
  87. } else {
  88. UserExample userExample = new UserExample();
  89. userExample.createCriteria().andRoleIdEqualTo(ConstantDataField.SALESMAN_ROLE_ID);
  90. users = userService.selectByExample(userExample);
  91. }
  92. m.addAttribute("users", users);
  93. return "customer/add";
  94. }
  95. @ResponseBody
  96. @RequestMapping("/insert")
  97. @RequiresPermissions("customer:insert")
  98. public Boolean insert(Customer customer){
  99. int res = customerService.insert(customer);
  100. if (res == 1) {
  101. return true;
  102. }
  103. return false;
  104. }
  105. @RequestMapping("/edit")
  106. @RequiresPermissions("customer:update")
  107. public String edit(Model m, Long customerId) {
  108. //查出地区列表
  109. BasicDataExample basicDataExample = new BasicDataExample();
  110. basicDataExample.createCriteria().andParentIdEqualTo(ConstantDataField.AREA_BASICDATA_ID);
  111. List<BasicData> basicDatas= basicDataService.selectByExample(basicDataExample);
  112. m.addAttribute("areas",basicDatas);
  113. //查出业务员
  114. UserExample userExample = new UserExample();
  115. userExample.createCriteria().andRoleIdEqualTo(ConstantDataField.SALESMAN_ROLE_ID);
  116. List<User> users = userService.selectByExample(userExample);
  117. m.addAttribute("users", users);
  118. //查出当前客户
  119. Customer customer = customerService.selectByPrimaryKey(customerId);
  120. m.addAttribute("customer", customer);
  121. return "customer/edit";
  122. }
  123. @ResponseBody
  124. @RequestMapping("/update")
  125. @RequiresPermissions("customer:update")
  126. public Boolean update(Customer customer) {
  127. int res = customerService.updateByPrimaryKeySelective(customer);
  128. if (res == 1) {
  129. return true;
  130. }
  131. return false;
  132. }
  133. }

后台管理控制层:

  1. @Controller
  2. @RequestMapping("/admin")
  3. public class AdminController {
  4. @Autowired
  5. private UserService userService;
  6. @Autowired
  7. private RoleService roleService;
  8. @RequestMapping("/list")
  9. @RequiresPermissions("admin:list")
  10. public String adminList() {
  11. return "admin/list";
  12. }
  13. /**
  14. * 该方法返回 admin 集合的 JSON 字符串,使用 PageHelper 工具进行分页
  15. * @param keyWord 搜索关键字
  16. * @param pageNum 页数,默认为 1
  17. * @param pageSize 每个页面用户容量,默认为 10/页
  18. * @return
  19. */
  20. @ResponseBody
  21. @RequestMapping("/getAdmins")
  22. @RequiresPermissions("admin:list")
  23. public PageInfo<User> getAdmins(String keyWord,
  24. @RequestParam(defaultValue = "1") Integer pageNum,
  25. @RequestParam(defaultValue = "10") Integer pageSize) {
  26. //开始分页,这里启动并设置页码,和每页结果数量后,后续结果会自动为分页后结果
  27. PageHelper.startPage(pageNum, pageSize);
  28. UserExample userExample = new UserExample();
  29. /**
  30. * StringUtils.isNotBlank 可以判断 ""/" "/nullfalse
  31. */
  32. if (StringUtils.isNotBlank(keyWord)) {
  33. //用户名条件
  34. UserExample.Criteria criteriaUserName = userExample.createCriteria();
  35. criteriaUserName.andUsernameLike("%" + keyWord + "%");
  36. //真实名字条件
  37. UserExample.Criteria criteriaRealName = userExample.createCriteria();
  38. criteriaRealName.andRealnameLike("%" + keyWord + "%");
  39. //将两个条件用 or 组合
  40. userExample.or(criteriaRealName);
  41. }
  42. List<User> users = userService.selectByExample(userExample);
  43. //获得分页对象
  44. PageInfo<User> pageInfo = new PageInfo<>(users);
  45. return pageInfo;
  46. }
  47. @ResponseBody
  48. @RequestMapping("/delete")
  49. @RequiresPermissions("admin:delete")
  50. public Map<String, String> delete(Long[] userIds) {
  51. HashMap<String, String> map = new HashMap<>();
  52. if (userIds.length == 1) {
  53. int res = userService.deleteByPrimaryKey(userIds[0]);
  54. if (res == 1) {
  55. map.put("status", "true");
  56. map.put("info", "删除成功!");
  57. return map;
  58. }
  59. map.put("status", "false");
  60. map.put("info", "删除失败!用户已经不存在");
  61. return map;
  62. }
  63. //批量删除
  64. int success = 0;
  65. int total = userIds.length;
  66. for(Long userId : userIds) {
  67. success += userService.deleteByPrimaryKey(userId);
  68. }
  69. map.put("status", "true");
  70. map.put("info", "成功删除选中 " + total + " 个用户中的 " + success + " 个用户");
  71. return map;
  72. }
  73. @RequiresPermissions("admin:insert")
  74. @RequestMapping("/add")
  75. public String addAdmin(Model m) {
  76. RoleExample roleExample = new RoleExample();
  77. List<Role> roles = roleService.selectByExample(roleExample);
  78. m.addAttribute("roles", roles);
  79. return "admin/add";
  80. }
  81. @ResponseBody
  82. @RequestMapping("/checkUsername")
  83. @RequiresPermissions("admin:list")
  84. public Boolean checkUsername(String username) {
  85. UserExample userExample = new UserExample();
  86. UserExample.Criteria criteria = userExample.createCriteria();
  87. criteria.andUsernameEqualTo(username);
  88. System.out.println(userService.selectByExample(userExample));
  89. if (userService.selectByExample(userExample).size() != 0) {
  90. return false;
  91. }
  92. return true;
  93. }
  94. @ResponseBody
  95. @RequestMapping("/insert")
  96. @RequiresPermissions("admin:insert")
  97. public Boolean insert(User user){
  98. String salt = UUID.randomUUID().toString().substring(0, 4);
  99. String hashedPassword = new SimpleHash("md5", user.getPassword(), salt,3).toString();
  100. user.setSalt(salt);
  101. user.setPassword(hashedPassword);
  102. user.setCreateDate(new Date());
  103. int res = userService.insert(user);
  104. if (res == 1) {
  105. return true;
  106. }
  107. return false;
  108. }
  109. @RequestMapping("/edit")
  110. @RequiresPermissions("admin:update")
  111. public String edit(Model m, Long userId) {
  112. m.addAttribute("user", userService.selectByPrimaryKey(userId));
  113. m.addAttribute("roles", roleService.selectByExample(new RoleExample()));
  114. return "admin/edit";
  115. }
  116. @ResponseBody
  117. @RequestMapping("/update")
  118. @RequiresPermissions("admin:update")
  119. public Boolean update(User user) {
  120. if (StringUtils.isBlank(user.getPassword())) {
  121. user.setPassword(null);
  122. } else {
  123. String salt = UUID.randomUUID().toString().substring(0, 4);
  124. String hashedPassword = new SimpleHash("md5", user.getPassword(), salt, 3).toString();
  125. user.setPassword(hashedPassword);
  126. user.setSalt(salt);
  127. }
  128. int res = userService.updateByPrimaryKeySelective(user);
  129. if (res == 1) {
  130. return true;
  131. }
  132. return false;
  133. }
  134. }

订单管理控制层:

  1. @Controller
  2. @RequestMapping("/order")
  3. public class OrderController {
  4. @Autowired
  5. private OrderViewService orderViewService;
  6. @Autowired
  7. private OrderService orderService;
  8. @Autowired
  9. private UserService userService;
  10. @Autowired
  11. private CustomerService customerService;
  12. @Autowired
  13. private BasicDataService basicDataService;
  14. @Autowired
  15. private OrderDetailService orderDetailService;
  16. //工具方法
  17. public PageInfo<OrderView> getOrdersUtil(String keyWord, Integer pageNum, Integer pageSize) {
  18. //开始分页,这里启动并设置页码,和每页结果数量后,后续结果会自动为分页后结果
  19. PageHelper.startPage(pageNum, pageSize);
  20. OrderViewExample orderViewExample = new OrderViewExample();
  21. OrderViewExample.Criteria criteria = orderViewExample.createCriteria();
  22. /**
  23. * StringUtils.isNotBlank 可以判断 ""/" "/nullfalse
  24. */
  25. if (StringUtils.isNotBlank(keyWord)) {
  26. //客户名条件
  27. criteria.andCustomerNameLike("%" + keyWord + "%");
  28. }
  29. //判断当前登录用户是否为业务员,业务员只能查看自己的订单
  30. Subject subject = SecurityUtils.getSubject();
  31. User user = (User) subject.getPrincipal();
  32. if (user.getRoleId() == ConstantDataField.SALESMAN_ROLE_ID) {
  33. //客户的业务员用户名等于登录用户的用户名
  34. criteria.andUsernameEqualTo(user.getUsername());
  35. }
  36. List<OrderView> orders = orderViewService.selectByExample(orderViewExample);
  37. //获得分页对象
  38. PageInfo<OrderView> pageInfo = new PageInfo<>(orders);
  39. return pageInfo;
  40. }
  41. @RequestMapping("/list")
  42. @RequiresPermissions("order:list")
  43. public String list() {
  44. return "order/list";
  45. }
  46. @ResponseBody
  47. @RequestMapping("/getOrders")
  48. @RequiresPermissions("order:list")
  49. public PageInfo<OrderView> getOrders(String keyWord,
  50. @RequestParam(defaultValue = "1") Integer pageNum,
  51. @RequestParam(defaultValue = "10") Integer pageSize) {
  52. return getOrdersUtil(keyWord, pageNum, pageSize);
  53. }
  54. @ResponseBody
  55. @RequestMapping("/delete")
  56. @RequiresPermissions("order:delete")
  57. public Map<String, String> delete(Long[] orderIds) {
  58. HashMap<String, String> map = new HashMap<>();
  59. //单个删除
  60. if (orderIds.length == 1) {
  61. int res = orderService.deleteByPrimaryKey(orderIds[0]);
  62. if (res == 1) {
  63. map.put("status", "true");
  64. map.put("info", "删除成功!");
  65. return map;
  66. }
  67. map.put("status", "false");
  68. map.put("info", "删除失败!订单已经不存在");
  69. return map;
  70. }
  71. //批量删除
  72. int success = 0;
  73. int total = orderIds.length;
  74. for(Long orderId : orderIds) {
  75. success += orderService.deleteByPrimaryKey(orderId);
  76. }
  77. map.put("status", "true");
  78. map.put("info", "成功删除选中 " + total + " 个订单中的 " + success + " 个订单");
  79. return map;
  80. }
  81. @RequestMapping("/add")
  82. @RequiresPermissions("order:insert")
  83. public String add(Model m) {
  84. this.getOrderGeneralData(m);
  85. return "order/add";
  86. }
  87. /*
  88. 用 @RequestBody 注解,将前台传入的 JSON 字符串解析成对象
  89. */
  90. @RequestMapping("/insert")
  91. @RequiresPermissions("order:insert")
  92. @ResponseBody
  93. @Transactional(isolation = Isolation.REPEATABLE_READ, propagation = Propagation.REQUIRED, timeout = 5)
  94. public Boolean insert(@RequestBody Order order) {
  95. //插入 order,在此之后,order 获得了 orderId
  96. int res = orderService.insert(order);
  97. //获取订单详情集合
  98. List<OrderDetail> orderDetails = order.getorderDetails();
  99. orderDetails.forEach(orderDetail -> {
  100. orderDetail.setOrderId(order.getOrderId());
  101. orderDetailService.insert(orderDetail);
  102. });
  103. if (res == 1) {
  104. return true;
  105. }
  106. return false;
  107. }
  108. @RequestMapping("/edit")
  109. @RequiresPermissions("order:update")
  110. public String edit(Long orderId, Model m) {
  111. //获取常规数据
  112. getOrderGeneralData(m);
  113. //添加选中的订单
  114. Order selectedOrder = orderService.selectByPrimaryKey(orderId);
  115. m.addAttribute("selectedOrder", selectedOrder);
  116. //添加订单详情
  117. OrderDetailExample orderDetailExample = new OrderDetailExample();
  118. orderDetailExample.createCriteria().andOrderIdEqualTo(orderId);
  119. List<OrderDetail> orderDetails = orderDetailService.selectByExample(orderDetailExample);
  120. m.addAttribute("orderDetails", orderDetails);
  121. return "order/edit";
  122. }
  123. @RequiresPermissions("order:update")
  124. @RequestMapping("/update")
  125. @ResponseBody
  126. public Boolean update(@RequestBody Order order) {
  127. OrderDetailExample orderDetailExample = new OrderDetailExample();
  128. orderDetailExample.createCriteria().andOrderIdEqualTo(order.getOrderId());
  129. List<OrderDetail> dbOrderDetails = orderDetailService.selectByExample(orderDetailExample); //数据库中的orderDetails
  130. List<OrderDetail> formOrderDetails = order.getorderDetails(); //表单数据中的orderDetails
  131. //循环比较数据库数据和表单新数据,删除数据库中在修改中删除的数据
  132. dbOrderDetails.forEach(dbOrderDetail -> {
  133. if (!formOrderDetails.contains(dbOrderDetail)) {
  134. orderDetailService.deleteByPrimaryKey(dbOrderDetail.getOrderDetailId());
  135. }
  136. });
  137. //循环比较表单新数据和数据库数据,若存在则修改,不存在则新增
  138. formOrderDetails.forEach(formOrderDetail -> {
  139. if (dbOrderDetails.contains(formOrderDetail)) {
  140. orderDetailService.updateByPrimaryKeySelective(formOrderDetail);
  141. } else {
  142. formOrderDetail.setOrderId(order.getOrderId());
  143. orderDetailService.insert(formOrderDetail);
  144. }
  145. });
  146. //修改Order
  147. int res = orderService.updateByPrimaryKey(order);
  148. if (res == 1){
  149. return true;
  150. }
  151. return false;
  152. }
  153. //抽取的工具方法
  154. private void getOrderGeneralData(Model m){
  155. User user = (User)SecurityUtils.getSubject().getPrincipal(); //获取当前用户
  156. Long userRoleId = user.getRoleId(); //当前用户角色ID
  157. Long userId = user.getUserId(); //当前用户ID
  158. //查找业务员
  159. UserExample userExample = new UserExample();
  160. List<User> users = new ArrayList<>();
  161. //如果当前用户是业务员只能用自己用户添加
  162. if (userRoleId == ConstantDataField.SALESMAN_ROLE_ID) {
  163. users.add(userService.selectByPrimaryKey(userId));
  164. } else {
  165. userExample.createCriteria().andRoleIdEqualTo(ConstantDataField.SALESMAN_ROLE_ID);
  166. users = userService.selectByExample(userExample);
  167. }
  168. m.addAttribute("users", users);
  169. //查找客户
  170. CustomerExample customerExample = new CustomerExample();
  171. List<Customer> customers;
  172. //如果当前用户是业务员只能获得自己的客户
  173. if (userRoleId == ConstantDataField.SALESMAN_ROLE_ID) {
  174. customerExample.createCriteria().andUserIdEqualTo(userId);
  175. customers = customerService.selectByExample(customerExample);
  176. } else {
  177. customers = customerService.selectByExample(customerExample);
  178. }
  179. m.addAttribute("customers", customers);
  180. //查找地区
  181. BasicDataExample areaExample = new BasicDataExample();
  182. areaExample.createCriteria().andParentIdEqualTo(ConstantDataField.AREA_BASICDATA_ID);
  183. List<BasicData> areas = basicDataService.selectByExample(areaExample);
  184. m.addAttribute("areas", areas);
  185. //查找付款方式
  186. BasicDataExample paymentExample = new BasicDataExample();
  187. paymentExample.createCriteria().andParentIdEqualTo(ConstantDataField.PAYMENT_BASICDATA_ID);
  188. List<BasicData> payments = basicDataService.selectByExample(paymentExample);
  189. m.addAttribute("payments", payments);
  190. //查找运送方式
  191. BasicDataExample transportExample = new BasicDataExample();
  192. transportExample.createCriteria().andParentIdEqualTo(ConstantDataField.TRANSPORT_BASICDATA_ID);
  193. List<BasicData> transports = basicDataService.selectByExample(transportExample);
  194. m.addAttribute("transports", transports);
  195. //查找取件方式
  196. BasicDataExample pickupExample = new BasicDataExample();
  197. pickupExample.createCriteria().andParentIdEqualTo(ConstantDataField.PICKUP_BASICDATA_ID);
  198. List<BasicData> pickups = basicDataService.selectByExample(pickupExample);
  199. m.addAttribute("pickups", pickups);
  200. //查找单位
  201. BasicDataExample unitExample = new BasicDataExample();
  202. unitExample.createCriteria().andParentIdEqualTo(ConstantDataField.UNIT_BASICDATA_ID);
  203. List<BasicData> units = basicDataService.selectByExample(unitExample);
  204. m.addAttribute("units", units);
  205. }
  206. }

 

源码获取:博客首页 "资源" 里下载! 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/155648
推荐阅读
相关标签
  

闽ICP备14008679号