当前位置:   article > 正文

基于javaweb+mysql的springboot校园物流快递管理系统(java+maven+thymeleaf+html+springboot+layui+mysql)_基于java的快递管理系统

基于java的快递管理系统

基于javaweb+mysql的springboot校园物流快递管理系统(java+maven+thymeleaf+html+springboot+layui+mysql)

运行环境

Java≥8、MySQL≥5.7

开发工具

eclipse/idea/myeclipse/sts等均可配置运行

适用

课程设计,大作业,毕业设计,项目练习,学习演示等

功能说明

基于javaweb+mysql的SpringBoot校园物流快递管理系统(java+maven+thymeleaf+html+springboot+layui+mysql)

一、项目运行 环境配置:

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

项目技术:

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

            attributes.addFlashAttribute("message", "权限不足,请先登录");
            return "redirect:/toLogin";
        }
    }

    @PostMapping("/updateUserInfo")
    public String updateUserInfo(User user, HttpSession session) {
        User userInfo = (User) session.getAttribute("user");
        Integer id = userInfo.getId();
        user.setId(id);
        userService.updateById(user);
        return "redirect:/toUserInfo";
    }

    @GetMapping("/findByName")
    @ResponseBody
    public void findName(String name, HttpSession session, HttpServletResponse response) throws IOException {
        User nowUser = (User) session.getAttribute("user");
        Integer id = nowUser.getId();
        response.setContentType("application/json;charset=utf-8");
        QueryWrapper<User> wrapper = new QueryWrapper<User>().eq("name", name).ne("id", id);
        User userInfo = userService.getOne(wrapper);
        Map<String, Object> map = new HashMap<>();
        if (userInfo != null) {
            map.put("nameExit", true);
            map.put("msg", "用户名已存在");
        } else {
            map.put("nameExit", false);
            map.put("msg", "正确");
        }
        //将map转为json,并且传递给客户端
        String s = JSON.toJSONString(map);
        PrintWriter writer = response.getWriter();
        writer.write(s);
        writer.close();
    }

    @RequestMapping("/uploadAvatar")
    public String uploadAvatar(@RequestParam("file") MultipartFile file, HttpSession session) {
        String filename = file.getOriginalFilename();
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
        postService.updatePostStatusTo2(id, new Date());

        return "redirect:/toAdminSend";
    }

    //用户管理
    @GetMapping("/toAdminUser")
    public String toAdminUser(@RequestParam(required = false, defaultValue = "1", value = "pageNum") int pageNum, HttpSession session, Model model, RedirectAttributes attributes) {
        User userInfo = (User) session.getAttribute("user");
        if (userInfo != null) {
            PageHelper.startPage(pageNum, 6);
            List<User> userList = userService.list();
            PageInfo<User> pageInfo = new PageInfo<>(userList);
            model.addAttribute("userList", userList);
            model.addAttribute("pageInfo", pageInfo);
            return "adminUser";
        } else {
            attributes.addFlashAttribute("message", "权限不足,请先登录");
            return "redirect:/toLogin";
        }
    }

    @GetMapping("/adminUserTo1/{id}")
    public String adminUserTo1(@PathVariable Integer id, HttpSession session) {
        User user = userService.getById(id);
        user.setRole(1);
        userService.updateById(user);

        User userInfo = (User) session.getAttribute("user");
        if (id == userInfo.getId()) {
            session.setAttribute("user", user);
            return "index";
        }
        return "redirect:/toAdminUser";
    }

    @GetMapping("/adminUserTo0/{id}")
    public String adminUserTo0(@PathVariable Integer id) {
        User user = userService.getById(id);
        user.setRole(0);
        userService.updateById(user);
        return "redirect:/toAdminUser";
    }

}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
    UserService userService;

    //寄件管理
    @GetMapping("/toAdminSend")
    public String toAdminSend(@RequestParam(required = false, defaultValue = "1", value = "pageNum") int pageNum, HttpSession session, Model model, RedirectAttributes attributes) {
        User userInfo = (User) session.getAttribute("user");
        if (userInfo != null) {
            PageHelper.startPage(pageNum, 6);
            List<Post> postList = postService.findAllPost();
            PageInfo<Post> pageInfo = new PageInfo<>(postList);
            model.addAttribute("postList", postList);
            model.addAttribute("pageInfo", pageInfo);
            List<Category> categoryList = categoryService.list();
            model.addAttribute("categoryList", categoryList);
            return "adminSend";
        } else {
            attributes.addFlashAttribute("message", "权限不足,请先登录");
            return "redirect:/toLogin";
        }
    }

    @GetMapping("adminSendPost/{id}")
    public String adminSendPost(@PathVariable Integer id) {
        postService.updatePostStatusTo1(id, new Date());
        return "redirect:/toAdminSend";
    }

    @PostMapping("/searchPost")
    public String searchPost(Post post, @RequestParam(required = false, defaultValue = "1", value = "pageNum") int pageNum, Model model) {
        PageHelper.startPage(pageNum, 6);
        List<Post> postList = postService.findPostBySearch(post);
        PageInfo<Post> pageInfo = new PageInfo<>(postList);
        List<Category> categoryList = categoryService.list();
        model.addAttribute("categoryList", categoryList);
        model.addAttribute("postList", postList);
        model.addAttribute("pageInfo", pageInfo);
        return "adminSend";
    }

    //收件管理
    @GetMapping("adminPickUpPost/{id}")
    public String adminPickUpPost(@PathVariable Integer id, Model model) {
        Post post = postService.findById(id);
        model.addAttribute("post", post);
        QueryWrapper<Position> status0 = new QueryWrapper<Position>().eq("status", 0);
        List<Position> positionList = positionService.list(status0);
        model.addAttribute("positionList", positionList);
        return "adminPickUp";
    }

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
    @Autowired
    UserService userService;

    @GetMapping("/toLogin")
    public String toLogin(){
        return "login";
    }

    @PostMapping("/userLogin")
    public String login(@RequestParam String username, @RequestParam String password,
                        HttpSession session, RedirectAttributes attributes) {
        QueryWrapper<User> wrapper = new QueryWrapper<User>().eq("username", username).eq("password", password);
        User user = userService.getOne(wrapper);
        if (user != null){
            session.setAttribute("user",user);
            return "redirect:/index";
        }else {
            attributes.addFlashAttribute("message","用户名或密码错误");
            return "redirect:/toLogin";
        }
    }

    @GetMapping("/toRegister")
    public String toRegister() {
        return "register";
    }

    @PostMapping("/register")
    public String register(User user) {
        user.setCreateTime(new Date());
        userService.save(user);
        return "redirect:/toLogin";
    }

    @GetMapping("/findUsername")
    @ResponseBody
    public void findUsername(String username, HttpServletResponse response) throws IOException {
        response.setContentType("application/json;charset=utf-8");
        QueryWrapper<User> wrapper = new QueryWrapper<User>().eq("username", username);
        User userInfo = userService.getOne(wrapper);
        Map<String, Object> map = new HashMap<>();
        if (userInfo != null) {
            map.put("userExit", true);
            map.put("msg", "用户名已存在");
        } else {
            map.put("userExit", false);
            map.put("msg", "正确");
        }
        //将map转为json,并且传递给客户端
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49

/**
 */
@Controller
public class SendController {

    @Autowired
    PostService postService;

    @GetMapping("/toSend")
    public String toSend(HttpSession session, RedirectAttributes attributes){
        User userInfo = (User) session.getAttribute("user");
        if (userInfo != null) {
            return "send";
        } else {
            attributes.addFlashAttribute("message", "权限不足,请先登录");
            return "redirect:/toLogin";
        }
    }

    @PostMapping("/sendPost")
    public String sendPost(Post post,HttpSession session){
        User user = (User) session.getAttribute("user");
        post.setUserId(user.getId());
        post.setCreateTime(new Date());
        post.setUpdateTime(new Date());
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
        String format = dateFormat.format(new Date());
        String num = format.concat(String.valueOf(user.getId()));
        String postNum = num.concat("2");
        post.setNum(postNum);
        postService.save(post);
        return "redirect:/toUserSend";
    }

    @PostMapping("/updatePost")
    public String updatePost(Post post){
        post.setUpdateTime(new Date());
        postService.updateById(post);
        return "redirect:/toUserSend";
    }

}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43

/**
 */
@Controller
public class adminController {

    @Autowired
    PostService postService;

    @Autowired
    CategoryService categoryService;

    @Autowired
    PositionService positionService;

    @Autowired
    OrdersService ordersService;

    @Autowired
    UserService userService;

    //寄件管理
    @GetMapping("/toAdminSend")
    public String toAdminSend(@RequestParam(required = false, defaultValue = "1", value = "pageNum") int pageNum, HttpSession session, Model model, RedirectAttributes attributes) {
        User userInfo = (User) session.getAttribute("user");
        if (userInfo != null) {
            PageHelper.startPage(pageNum, 6);
            List<Post> postList = postService.findAllPost();
            PageInfo<Post> pageInfo = new PageInfo<>(postList);
            model.addAttribute("postList", postList);
            model.addAttribute("pageInfo", pageInfo);
            List<Category> categoryList = categoryService.list();
            model.addAttribute("categoryList", categoryList);
            return "adminSend";
        } else {
            attributes.addFlashAttribute("message", "权限不足,请先登录");
            return "redirect:/toLogin";
        }
    }

    @GetMapping("adminSendPost/{id}")
    public String adminSendPost(@PathVariable Integer id) {
        postService.updatePostStatusTo1(id, new Date());
        return "redirect:/toAdminSend";
    }

    @PostMapping("/searchPost")
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47

/**
 */
@Controller
public class PickUpController {

    @Autowired
    OrdersService ordersService;

    @Autowired
    PositionService positionService;

    @Autowired
    PostService postService;

    @GetMapping("/toPickUp")
    public String toPickUp(@RequestParam(required = false, defaultValue = "1", value = "pageNum") int pageNum, Model model, HttpSession session, RedirectAttributes attributes) {
        User userInfo = (User) session.getAttribute("user");
        if (userInfo != null) {
            PageHelper.startPage(pageNum, 6);
            List<Orders> ordersList = ordersService.findByUserId(userInfo.getId());
            PageInfo<Orders> pageInfo = new PageInfo<>(ordersList);
            model.addAttribute("ordersList",ordersList);
            model.addAttribute("pageInfo",pageInfo);
            return "pickUp";
        } else {
            attributes.addFlashAttribute("message", "权限不足,请先登录");
            return "redirect:/toLogin";
        }
    }

    @GetMapping("/pickUpOrders/{id}")
    public String pickUpOrders(@PathVariable Integer id){
        ordersService.updateOrdersStatusTo1(id,new Date());
        Orders orders = ordersService.findById(id);
        //柜子状态变为0
        Position position = positionService.getById(orders.getPositionId());
        position.setStatus(0);
        positionService.updateById(position);
        //post状态变为3
        Post post = postService.findByNum(orders.getNum());
        postService.updatePostStatusTo3(post.getId(), new Date());

        return "redirect:/toPickUp";
    }

    @GetMapping("/pickUpOrders2/{id}")
    public String pickUpOrders2(@PathVariable Integer id){
        ordersService.updateOrdersStatusTo1(id,new Date());
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49

    @Autowired
    private AliyunOssUtil aliyunOssUtil;

    //个人信息
    @GetMapping("/toUserInfo")
    public String toUserInfo(HttpSession session, RedirectAttributes attributes) {

        User userInfo = (User) session.getAttribute("user");
        if (userInfo != null) {
            Integer id = userInfo.getId();
            User user = userService.getById(id);
            //更新
            session.setAttribute("user", user);
            return "userInfo";
        } else {
            attributes.addFlashAttribute("message", "权限不足,请先登录");
            return "redirect:/toLogin";
        }
    }

    @PostMapping("/updateUserInfo")
    public String updateUserInfo(User user, HttpSession session) {
        User userInfo = (User) session.getAttribute("user");
        Integer id = userInfo.getId();
        user.setId(id);
        userService.updateById(user);
        return "redirect:/toUserInfo";
    }

    @GetMapping("/findByName")
    @ResponseBody
    public void findName(String name, HttpSession session, HttpServletResponse response) throws IOException {
        User nowUser = (User) session.getAttribute("user");
        Integer id = nowUser.getId();
        response.setContentType("application/json;charset=utf-8");
        QueryWrapper<User> wrapper = new QueryWrapper<User>().eq("name", name).ne("id", id);
        User userInfo = userService.getOne(wrapper);
        Map<String, Object> map = new HashMap<>();
        if (userInfo != null) {
            map.put("nameExit", true);
            map.put("msg", "用户名已存在");
        } else {
            map.put("nameExit", false);
            map.put("msg", "正确");
        }
        //将map转为json,并且传递给客户端
        String s = JSON.toJSONString(map);
        PrintWriter writer = response.getWriter();
        writer.write(s);
        writer.close();
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
    public String adminSendPost(@PathVariable Integer id) {
        postService.updatePostStatusTo1(id, new Date());
        return "redirect:/toAdminSend";
    }

    @PostMapping("/searchPost")
    public String searchPost(Post post, @RequestParam(required = false, defaultValue = "1", value = "pageNum") int pageNum, Model model) {
        PageHelper.startPage(pageNum, 6);
        List<Post> postList = postService.findPostBySearch(post);
        PageInfo<Post> pageInfo = new PageInfo<>(postList);
        List<Category> categoryList = categoryService.list();
        model.addAttribute("categoryList", categoryList);
        model.addAttribute("postList", postList);
        model.addAttribute("pageInfo", pageInfo);
        return "adminSend";
    }

    //收件管理
    @GetMapping("adminPickUpPost/{id}")
    public String adminPickUpPost(@PathVariable Integer id, Model model) {
        Post post = postService.findById(id);
        model.addAttribute("post", post);
        QueryWrapper<Position> status0 = new QueryWrapper<Position>().eq("status", 0);
        List<Position> positionList = positionService.list(status0);
        model.addAttribute("positionList", positionList);
        return "adminPickUp";
    }

//    @GetMapping("/toAdminPickUp")
//    public String toAdminPickUp(Model model, RedirectAttributes attributes, HttpSession session) {
//        User userInfo = (User) session.getAttribute("user");
//        if (userInfo != null) {
//            QueryWrapper<Position> status0 = new QueryWrapper<Position>().eq("status", 0);
//            List<Position> positionList = positionService.list(status0);
//            model.addAttribute("positionList", positionList);
//            return "adminPickUp";
//        } else {
//            attributes.addFlashAttribute("message", "权限不足,请先登录");
//            return "redirect:/toLogin";
//        }
//    }

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
        }
    }

    @GetMapping("toPostDetail/{id}")
    public String toPostDetail(@PathVariable Integer id, Model model) {
        Post post = postService.findById(id);
        model.addAttribute("post",post);
        return "send3";
    }

    @GetMapping("toUpdatePost/{id}")
    public String toUpdatePost(@PathVariable Integer id, Model model) {
        Post post = postService.findById(id);
        model.addAttribute("post",post);
        return "send2";
    }

    @GetMapping("deletePost/{id}")
    public String deletePost(@PathVariable Integer id) {
        postService.removeById(id);
        return "redirect:/toUserSend";
    }

}

/**
 */
@Controller
public class LoginController {

    @Autowired
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
        orders.setUserId(user.getId());
        orders.setSendName(sendName);
        orders.setPositionId(positionId);
        orders.setCreateTime(new Date());
        orders.setUpdateTime(new Date());
        orders.setNum(num);
        ordersService.save(orders);
        //柜子状态变为1
        Position position = positionService.getById(positionId);
        position.setStatus(1);
        positionService.updateById(position);
        //post状态变为2
        postService.updatePostStatusTo2(id, new Date());

        return "redirect:/toAdminSend";
    }

    //用户管理
    @GetMapping("/toAdminUser")
    public String toAdminUser(@RequestParam(required = false, defaultValue = "1", value = "pageNum") int pageNum, HttpSession session, Model model, RedirectAttributes attributes) {
        User userInfo = (User) session.getAttribute("user");
        if (userInfo != null) {
            PageHelper.startPage(pageNum, 6);
            List<User> userList = userService.list();
            PageInfo<User> pageInfo = new PageInfo<>(userList);
            model.addAttribute("userList", userList);
            model.addAttribute("pageInfo", pageInfo);
            return "adminUser";
        } else {
            attributes.addFlashAttribute("message", "权限不足,请先登录");
            return "redirect:/toLogin";
        }
    }

    @GetMapping("/adminUserTo1/{id}")
    public String adminUserTo1(@PathVariable Integer id, HttpSession session) {
        User user = userService.getById(id);
        user.setRole(1);
        userService.updateById(user);

        User userInfo = (User) session.getAttribute("user");
        if (id == userInfo.getId()) {
            session.setAttribute("user", user);
            return "index";
        }
        return "redirect:/toAdminUser";
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
 */
@Controller
public class UserController {

    @Autowired
    UserService userService;

    @Autowired
    PostService postService;

    @Autowired
    OrdersService ordersService;

    @Autowired
    private AliyunOssUtil aliyunOssUtil;

    //个人信息
    @GetMapping("/toUserInfo")
    public String toUserInfo(HttpSession session, RedirectAttributes attributes) {

        User userInfo = (User) session.getAttribute("user");
        if (userInfo != null) {
            Integer id = userInfo.getId();
            User user = userService.getById(id);
            //更新
            session.setAttribute("user", user);
            return "userInfo";
        } else {
            attributes.addFlashAttribute("message", "权限不足,请先登录");
            return "redirect:/toLogin";
        }
    }

    @PostMapping("/updateUserInfo")
    public String updateUserInfo(User user, HttpSession session) {
        User userInfo = (User) session.getAttribute("user");
        Integer id = userInfo.getId();
        user.setId(id);
        userService.updateById(user);
        return "redirect:/toUserInfo";
    }

    @GetMapping("/findByName")
    @ResponseBody
    public void findName(String name, HttpSession session, HttpServletResponse response) throws IOException {
        User nowUser = (User) session.getAttribute("user");
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
        postService.removeById(id);
        return "redirect:/toUserSend";
    }

}

/**
 */
@Controller
public class LoginController {

    @Autowired
    UserService userService;

    @GetMapping("/toLogin")
    public String toLogin(){
        return "login";
    }

    @PostMapping("/userLogin")
    public String login(@RequestParam String username, @RequestParam String password,
                        HttpSession session, RedirectAttributes attributes) {
        QueryWrapper<User> wrapper = new QueryWrapper<User>().eq("username", username).eq("password", password);
        User user = userService.getOne(wrapper);
        if (user != null){
            session.setAttribute("user",user);
            return "redirect:/index";
        }else {
            attributes.addFlashAttribute("message","用户名或密码错误");
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29

/**
 */
@Controller
public class adminController {

    @Autowired
    PostService postService;

    @Autowired
    CategoryService categoryService;

    @Autowired
    PositionService positionService;

    @Autowired
    OrdersService ordersService;

    @Autowired
    UserService userService;

    //寄件管理
    @GetMapping("/toAdminSend")
    public String toAdminSend(@RequestParam(required = false, defaultValue = "1", value = "pageNum") int pageNum, HttpSession session, Model model, RedirectAttributes attributes) {
        User userInfo = (User) session.getAttribute("user");
        if (userInfo != null) {
            PageHelper.startPage(pageNum, 6);
            List<Post> postList = postService.findAllPost();
            PageInfo<Post> pageInfo = new PageInfo<>(postList);
            model.addAttribute("postList", postList);
            model.addAttribute("pageInfo", pageInfo);
            List<Category> categoryList = categoryService.list();
            model.addAttribute("categoryList", categoryList);
            return "adminSend";
        } else {
            attributes.addFlashAttribute("message", "权限不足,请先登录");
            return "redirect:/toLogin";
        }
    }

    @GetMapping("adminSendPost/{id}")
    public String adminSendPost(@PathVariable Integer id) {
        postService.updatePostStatusTo1(id, new Date());
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
                if (!"".equals(filename.trim())) {
                    File newFile = new File(filename);
                    FileOutputStream outputStream = new FileOutputStream(newFile);
                    outputStream.write(file.getBytes());
                    outputStream.close();
                    file.transferTo(newFile);
                    //返回图片的URL
                    String url = aliyunOssUtil.upLoad(newFile);
                    User userInfo = (User) session.getAttribute("user");
                    userInfo.setAvatar(url);
                    userService.saveOrUpdate(userInfo);
                }
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "redirect:/toUserInfo";
    }

    //我收到的
    @GetMapping("/toUserPickUp")
    public String toUserPickUp(@RequestParam(required = false, defaultValue = "1", value = "pageNum") int pageNum, HttpSession session, Model model, RedirectAttributes attributes) {
        User userInfo = (User) session.getAttribute("user");
        if (userInfo != null) {
            PageHelper.startPage(pageNum, 6);
            List<Orders> ordersList = ordersService.findAllByUserId(userInfo.getId());
            PageInfo<Orders> pageInfo = new PageInfo<>(ordersList);
            model.addAttribute("ordersList", ordersList);
            model.addAttribute("pageInfo", pageInfo);
            return "userPickUp";
        } else {
            attributes.addFlashAttribute("message", "权限不足,请先登录");
            return "redirect:/toLogin";
        }
    }

    //我寄出的
    @GetMapping("/toUserSend")
    public String toUserSend(@RequestParam(required = false, defaultValue = "1", value = "pageNum") int pageNum, HttpSession session, Model model, RedirectAttributes attributes) {
        User userInfo = (User) session.getAttribute("user");
        if (userInfo != null) {
            PageHelper.startPage(pageNum, 6);
            List<Post> postList = postService.findByUserId(userInfo.getId());
            PageInfo<Post> pageInfo = new PageInfo<>(postList);
            model.addAttribute("postList", postList);
            model.addAttribute("pageInfo", pageInfo);
            return "userSend";
        } else {
            attributes.addFlashAttribute("message", "权限不足,请先登录");
            return "redirect:/toLogin";
        }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
    }

    @GetMapping("/pickUpOrders/{id}")
    public String pickUpOrders(@PathVariable Integer id){
        ordersService.updateOrdersStatusTo1(id,new Date());
        Orders orders = ordersService.findById(id);
        //柜子状态变为0
        Position position = positionService.getById(orders.getPositionId());
        position.setStatus(0);
        positionService.updateById(position);
        //post状态变为3
        Post post = postService.findByNum(orders.getNum());
        postService.updatePostStatusTo3(post.getId(), new Date());

        return "redirect:/toPickUp";
    }

    @GetMapping("/pickUpOrders2/{id}")
    public String pickUpOrders2(@PathVariable Integer id){
        ordersService.updateOrdersStatusTo1(id,new Date());
        //柜子状态变为0
        Orders orders = ordersService.findById(id);
        Position position = positionService.getById(orders.getPositionId());
        position.setStatus(0);
        positionService.updateById(position);
        return "redirect:/toUserPickUp";
    }

}

/**
 */
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32

/**
 */
@Controller
public class UserController {

    @Autowired
    UserService userService;

    @Autowired
    PostService postService;

    @Autowired
    OrdersService ordersService;

    @Autowired
    private AliyunOssUtil aliyunOssUtil;

    //个人信息
    @GetMapping("/toUserInfo")
    public String toUserInfo(HttpSession session, RedirectAttributes attributes) {

        User userInfo = (User) session.getAttribute("user");
        if (userInfo != null) {
            Integer id = userInfo.getId();
            User user = userService.getById(id);
            //更新
            session.setAttribute("user", user);
            return "userInfo";
        } else {
            attributes.addFlashAttribute("message", "权限不足,请先登录");
            return "redirect:/toLogin";
        }
    }

    @PostMapping("/updateUserInfo")
    public String updateUserInfo(User user, HttpSession session) {
        User userInfo = (User) session.getAttribute("user");
        Integer id = userInfo.getId();
        user.setId(id);
        userService.updateById(user);
        return "redirect:/toUserInfo";
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42

请添加图片描述

请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述

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

闽ICP备14008679号