博主介绍:✌从事软件开发10年之余,专注于Java技术领域、Python人工智能及数据挖掘、小程序项目开发和Android项目开发等。CSDN、掘金、华为云、InfoQ、阿里云等平台优质作者✌
🍅文末获取源码联系🍅
👇🏻 精彩专栏推荐订阅👇🏻 不然下次找不到哟
————————————————
计算机毕业设计《1000套》✌
目录
1、项目介绍及开发技术
1.1 项目介绍
1.2 开发技术
2、系统功能设计结构图
3、功能截图
3.1 前台功能
3.2 后台功能
4、数据库表结构设计
5、关键代码
5.1 **Controller模块
5.2 **Service模块
5.3 **ServiceImpl模块
5.4 **Dao模块
6、论文目录结构
7、源码获取
1、项目介绍及开发技术
1.1 项目介绍
随着互联网技术的不断发展,人们的生活方式发生了巨大的变化。在这个信息化时代,人们越来越依赖于网络来获取信息、交流和解决问题。随着城市化进程的加快,越来越多的人涌入城市生活。然而,由于人口密度大、资源有限等原因,社区居民之间的物资交换需求逐渐增加。传统的线下交易方式效率低下,无法满足人们的需求。互联网技术的快速发展为社区物资交易提供了新的可能。通过互联网技术,人们可以实现信息的快速传递和共享,从而降低交易成本、提高交易效率。在这样的背景下,社区物资交易互助平台应运而生,为居民提供了一个便捷、高效的物资交换渠道。
基于Spring Boot的社区物资交易互助平台是一个典型的Web应用程序,它采用了目前流行的微服务架构,具有良好的可扩展性和可维护性。该平台的主要功能包括用户注册与登录、发布物资需求或提供物资、浏览物资列表、在线沟通等。通过这个平台,居民可以方便地找到自己需要的物资,同时也可以将自己的闲置物品提供给需要的人,实现资源的合理利用和共享。
本系统的设计现状和趋势涵盖了需求、结构、数据库等方面的设计,并实现了管理员和用户的特定功能。本文将从系统的设计、描述、实现、分析、测试等方面阐述开发过程。根据现实情况,本系统选择了可行的开发方案,并利用Java编程语言和MySQL数据库等技术实现了系统的全部功能。接下来,对系统进行了测试,以确保其无漏洞,并对用户权限进行了完善。最终,系统达到了相关标准。
1.2 开发技术
Java开发语言、SpringBoot、MyBatisPlus、MySQL数据库、Maven、IDEA开发工具、JDK1.8+、Vue、HTML、CSS、JS。
2、系统功能模块设计
用户:注册登录、首页、论坛、求助留言板、公告信息、物资、个人中心(个人中心、收货地址、物资收藏、物资订单、物资捐赠)。
管理员:登录、首页、个人中心(修改密码、个人信息)、管理员管理、基础数据管理(公告类型管理、物资类型管理、捐赠类型管理)、论坛管理、求助留言板管理、公告信息管理、物资管理(物资管理、物资收藏管理、物资订单管理)、用户管理、轮播图管理。
3、功能截图
3.1 前台功能
登录
首页
论坛
求助留言板
公告信息
物资
个人中心
3.2 后台功能
登录
首页
个人中心
管理员管理
基础数据管理
论坛管理
求助留言管理
公告信息管理
物资管理
物资捐赠管理
用户管理
轮播图管理
4、数据库表结构设计
/*
SQLyog Ultimate v11.3 (64 bit)
MySQL - 5.7.32-log : Database - shequwuzijiaoyipingtai
*********************************************************************
*/
/*!40101 SET NAMES utf8 */;
/*!40101 SET SQL_MODE=''*/;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
CREATE DATABASE /*!32312 IF NOT EXISTS*/`shequwuzijiaoyipingtai` /*!40100 DEFAULT CHARACTER SET utf8 */;
USE `shequwuzijiaoyipingtai`;
/*Table structure for table `address` */
DROP TABLE IF EXISTS `address`;
CREATE TABLE `address` (
`id` int(20) NOT NULL AUTO_INCREMENT COMMENT '主键 ',
`yonghu_id` int(20) NOT NULL COMMENT '创建用户',
`address_name` varchar(200) NOT NULL COMMENT '收货人 ',
`address_phone` varchar(200) NOT NULL COMMENT '电话 ',
`address_dizhi` varchar(200) NOT NULL COMMENT '地址 ',
`isdefault_types` int(11) NOT NULL COMMENT '是否默认地址 ',
`insert_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '添加时间',
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间',
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间 show3',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=utf8 COMMENT='收货地址';
/*Data for the table `address` */
insert into `address`(`id`,`yonghu_id`,`address_name`,`address_phone`,`address_dizhi`,`isdefault_types`,`insert_time`,`update_time`,`create_time`) values (1,2,'收货人1','17703786901','地址1',1,'2023-03-21 10:29:31','2023-03-21 10:29:31','2023-03-21 10:29:31'),(2,1,'收货人2','17703786902','地址2',1,'2023-03-21 10:29:31','2023-03-21 10:29:31','2023-03-21 10:29:31'),(3,3,'收货人3','17703786903','地址3',1,'2023-03-21 10:29:31','2023-03-21 10:29:31','2023-03-21 10:29:31'),(4,1,'收货人4','17703786904','地址4',1,'2023-03-21 10:29:31','2023-03-21 10:29:31','2023-03-21 10:29:31'),(5,3,'收货人5','17703786905','地址5',1,'2023-03-21 10:29:31','2023-03-21 10:29:31','2023-03-21 10:29:31'),(6,2,'收货人6','17703786906','地址6',1,'2023-03-21 10:29:31','2023-03-21 10:29:31','2023-03-21 10:29:31'),(7,3,'收货人7','17703786907','地址7',1,'2023-03-21 10:29:31','2023-03-21 10:29:31','2023-03-21 10:29:31'),(8,2,'收货人8','17703786908','地址8',1,'2023-03-21 10:29:31','2023-03-21 10:29:31','2023-03-21 10:29:31'),(9,1,'收货人9','17703786909','地址9',1,'2023-03-21 10:29:31','2023-03-21 10:29:31','2023-03-21 10:29:31'),(10,2,'收货人10','17703786910','地址10',1,'2023-03-21 10:29:31','2023-03-21 10:29:31','2023-03-21 10:29:31'),(11,3,'收货人11','17703786911','地址11',1,'2023-03-21 10:29:31','2023-03-21 10:29:31','2023-03-21 10:29:31'),(12,1,'收货人12','17703786912','地址12',1,'2023-03-21 10:29:31','2023-03-21 10:29:31','2023-03-21 10:29:31'),(13,1,'收货人13','17703786913','地址13',2,'2023-03-21 10:29:31','2023-03-21 10:55:28','2023-03-21 10:29:31'),(14,1,'收货人14','17703786914','地址14',1,'2023-03-21 10:29:31','2023-03-21 10:29:31','2023-03-21 10:29:31');
/*Table structure for table `config` */
DROP TABLE IF EXISTS `config`;
CREATE TABLE `config` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
`name` varchar(100) DEFAULT NULL COMMENT '配置参数名称',
`value` varchar(100) DEFAULT NULL COMMENT '配置参数值',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COMMENT='配置文件';
/*Data for the table `config` */
insert into `config`(`id`,`name`,`value`) values (1,'轮播图1','upload/config1.jpg'),(2,'轮播图2','upload/config2.jpg'),(3,'轮播图3','upload/config3.jpg');
/*Table structure for table `dictionary` */
DROP TABLE IF EXISTS `dictionary`;
CREATE TABLE `dictionary` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
`dic_code` varchar(200) DEFAULT NULL COMMENT '字段',
`dic_name` varchar(200) DEFAULT NULL COMMENT '字段名',
`code_index` int(11) DEFAULT NULL COMMENT '编码',
`index_name` varchar(200) DEFAULT NULL COMMENT '编码名字 Search111 ',
`super_id` int(11) DEFAULT NULL COMMENT '父字段id',
`beizhu` varchar(200) DEFAULT NULL COMMENT '备注',
`create_time` timestamp NULL DEFAULT NULL COMMENT '创建时间',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=59 DEFAULT CHARSET=utf8 COMMENT='字典';
/*Data for the table `dictionary` */
insert into `dictionary`(`id`,`dic_code`,`dic_name`,`code_index`,`index_name`,`super_id`,`beizhu`,`create_time`) values (38,'shangxia_types','上下架',1,'上架',NULL,NULL,'2023-03-21 10:29:19'),(39,'shangxia_types','上下架',2,'下架',NULL,NULL,'2023-03-21 10:29:19'),(40,'wuzi_types','物资类型',1,'物资类型1',NULL,NULL,'2023-03-21 10:29:19'),(41,'wuzi_types','物资类型',2,'物资类型2',NULL,NULL,'2023-03-21 10:29:19'),(42,'wuzi_types','物资类型',3,'物资类型3',NULL,NULL,'2023-03-21 10:29:19'),(43,'wuzi_collection_types','收藏表类型',1,'收藏',NULL,NULL,'2023-03-21 10:29:19'),(44,'wuzi_order_types','订单类型',101,'已支付',NULL,NULL,'2023-03-21 10:29:19'),(45,'wuzi_order_types','订单类型',102,'已退款',NULL,NULL,'2023-03-21 10:29:19'),(46,'wuzi_order_types','订单类型',103,'已派送',NULL,NULL,'2023-03-21 10:29:19'),(47,'wuzi_order_types','订单类型',104,'已收货',NULL,NULL,'2023-03-21 10:29:19'),(48,'wuzi_order_payment_types','订单支付类型',1,'余额',NULL,NULL,'2023-03-21 10:29:19'),(49,'isdefault_types','是否默认地址',1,'否',NULL,NULL,'2023-03-21 10:29:19'),(50,'isdefault_types','是否默认地址',2,'是',NULL,NULL,'2023-03-21 10:29:19'),(51,'wuzijuanzeng_types','捐赠类型',1,'捐赠类型1',NULL,NULL,'2023-03-21 10:29:19'),(52,'wuzijuanzeng_types','捐赠类型',2,'捐赠类型2',NULL,NULL,'2023-03-21 10:29:19'),(53,'news_types','公告类型',1,'公告类型1',NULL,NULL,'2023-03-21 10:29:19'),(54,'news_types','公告类型',2,'公告类型2',NULL,NULL,'2023-03-21 10:29:19'),(55,'sex_types','性别类型',1,'男',NULL,NULL,'2023-03-21 10:29:19'),(56,'sex_types','性别类型',2,'女',NULL,NULL,'2023-03-21 10:29:19'),(57,'forum_state_types','帖子状态',1,'发帖',NULL,NULL,'2023-03-21 10:29:19'),(58,'forum_state_types','帖子状态',2,'回帖',NULL,NULL,'2023-03-21 10:29:19');
/*Table structure for table `forum` */
DROP TABLE IF EXISTS `forum`;
CREATE TABLE `forum` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键',
`forum_name` varchar(200) DEFAULT NULL COMMENT '帖子标题 Search111 ',
`yonghu_id` int(11) DEFAULT NULL COMMENT '用户',
`users_id` int(11) DEFAULT NULL COMMENT '管理员',
`forum_content` longtext COMMENT '发布内容',
`super_ids` int(11) DEFAULT NULL COMMENT '父id',
`forum_state_types` int(11) DEFAULT NULL COMMENT '帖子状态',
`insert_time` timestamp NULL DEFAULT NULL COMMENT '发帖时间',
`update_time` timestamp NULL DEFAULT NULL COMMENT '修改时间',
`create_time` timestamp NULL DEFAULT NULL COMMENT '创建时间 show2',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=17 DEFAULT CHARSET=utf8 COMMENT='论坛';
/*Data for the table `forum` */
insert into `forum`(`id`,`forum_name`,`yonghu_id`,`users_id`,`forum_content`,`super_ids`,`forum_state_types`,`insert_time`,`update_time`,`create_time`) values (1,'帖子标题1',2,NULL,'发布内容1',383,1,'2023-03-21 10:29:31','2023-03-21 10:29:31','2023-03-21 10:29:31'),(2,'帖子标题2',1,NULL,'发布内容2',472,1,'2023-03-21 10:29:31','2023-03-21 10:29:31','2023-03-21 10:29:31'),(3,'帖子标题3',1,NULL,'发布内容3',254,1,'2023-03-21 10:29:31','2023-03-21 10:29:31','2023-03-21 10:29:31'),(4,'帖子标题4',3,NULL,'发布内容4',30,1,'2023-03-21 10:29:31','2023-03-21 10:29:31','2023-03-21 10:29:31'),(5,'帖子标题5',3,NULL,'发布内容5',174,1,'2023-03-21 10:29:31','2023-03-21 10:29:31','2023-03-21 10:29:31'),(6,'帖子标题6',1,NULL,'发布内容6',169,1,'2023-03-21 10:29:31','2023-03-21 10:29:31','2023-03-21 10:29:31'),(7,'帖子标题7',2,NULL,'发布内容7',487,1,'2023-03-21 10:29:31','2023-03-21 10:29:31','2023-03-21 10:29:31'),(8,'帖子标题8',1,NULL,'发布内容8',30,1,'2023-03-21 10:29:31','2023-03-21 10:29:31','2023-03-21 10:29:31'),(9,'帖子标题9',1,NULL,'发布内容9',1,1,'2023-03-21 10:29:31','2023-03-21 10:29:31','2023-03-21 10:29:31'),(10,'帖子标题10',1,NULL,'发布内容10',10,1,'2023-03-21 10:29:31','2023-03-21 10:29:31','2023-03-21 10:29:31'),(11,'帖子标题11',2,NULL,'发布内容11',353,1,'2023-03-21 10:29:31','2023-03-21 10:29:31','2023-03-21 10:29:31'),(12,'帖子标题12',2,NULL,'发布内容12',121,1,'2023-03-21 10:29:31','2023-03-21 10:29:31','2023-03-21 10:29:31'),(13,'帖子标题13',3,NULL,'发布内容13',65,1,'2023-03-21 10:29:31','2023-03-21 10:29:31','2023-03-21 10:29:31'),(14,'帖子标题14',2,NULL,'发布内容14',209,1,'2023-03-21 10:29:31','2023-03-21 10:29:31','2023-03-21 10:29:31'),(15,NULL,1,NULL,'论坛讨论11111',14,2,'2023-03-21 10:56:39',NULL,'2023-03-21 10:56:39'),(16,NULL,NULL,1,'123123',14,2,'2023-03-21 10:57:27',NULL,'2023-03-21 10:57:27');
/*Table structure for table `liuyan` */
DROP TABLE IF EXISTS `liuyan`;
CREATE TABLE `liuyan` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键 ',
`yonghu_id` int(11) DEFAULT NULL COMMENT '用户',
`liuyan_name` varchar(200) DEFAULT NULL COMMENT '留言标题 Search111 ',
`liuyan_text` longtext COMMENT '留言内容',
`insert_time` timestamp NULL DEFAULT NULL COMMENT '留言时间',
`reply_text` longtext COMMENT '回复内容',
`update_time` timestamp NULL DEFAULT NULL COMMENT '回复时间',
`create_time` timestamp NULL DEFAULT NULL COMMENT '创建时间 show2 nameShow',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=16 DEFAULT CHARSET=utf8 COMMENT='求助留言板';
/*Data for the table `liuyan` */
insert into `liuyan`(`id`,`yonghu_id`,`liuyan_name`,`liuyan_text`,`insert_time`,`reply_text`,`update_time`,`create_time`) values (1,1,'留言标题1','留言内容1','2023-03-21 10:29:31','回复信息1','2023-03-21 10:29:31','2023-03-21 10:29:31'),(2,3,'留言标题2','留言内容2','2023-03-21 10:29:31','回复信息2','2023-03-21 10:29:31','2023-03-21 10:29:31'),(3,3,'留言标题3','留言内容3','2023-03-21 10:29:31','回复信息3','2023-03-21 10:29:31','2023-03-21 10:29:31'),(4,1,'留言标题4','留言内容4','2023-03-21 10:29:31','回复信息4','2023-03-21 10:29:31','2023-03-21 10:29:31'),(5,3,'留言标题5','留言内容5','2023-03-21 10:29:31','回复信息5','2023-03-21 10:29:31','2023-03-21 10:29:31'),(6,3,'留言标题6','留言内容6','2023-03-21 10:29:31','回复信息6','2023-03-21 10:29:31','2023-03-21 10:29:31'),(7,2,'留言标题7','留言内容7','2023-03-21 10:29:31','回复信息7','2023-03-21 10:29:31','2023-03-21 10:29:31'),(8,3,'留言标题8','留言内容8','2023-03-21 10:29:31','回复信息8','2023-03-21 10:29:31','2023-03-21 10:29:31'),(9,3,'留言标题9','留言内容9','2023-03-21 10:29:31','回复信息9','2023-03-21 10:29:31','2023-03-21 10:29:31'),(10,2,'留言标题10','留言内容10','2023-03-21 10:29:31','回复信息10','2023-03-21 10:29:31','2023-03-21 10:29:31'),(11,1,'留言标题11','留言内容11','2023-03-21 10:29:31','回复信息11','2023-03-21 10:29:31','2023-03-21 10:29:31'),(12,1,'留言标题12','留言内容12','2023-03-21 10:29:31','回复信息12','2023-03-21 10:29:31','2023-03-21 10:29:31'),(13,3,'留言标题13','留言内容13','2023-03-21 10:29:31','回复信息13','2023-03-21 10:29:31','2023-03-21 10:29:31'),(14,1,'留言标题14','留言内容14','2023-03-21 10:29:31','回复信息14','2023-03-21 10:29:31','2023-03-21 10:29:31'),(15,1,'3546','12312','2023-03-21 10:56:26','12312123','2023-03-21 10:57:34','2023-03-21 10:56:26');
/*Table structure for table `news` */
DROP TABLE IF EXISTS `news`;
CREATE TABLE `news` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键',
`news_name` varchar(200) DEFAULT NULL COMMENT '公告标题 Search111 ',
`news_types` int(11) DEFAULT NULL COMMENT '公告类型 Search111 ',
`news_photo` varchar(200) DEFAULT NULL COMMENT '公告图片',
`insert_time` timestamp NULL DEFAULT NULL COMMENT '添加时间',
`news_content` longtext COMMENT '公告详情',
`create_time` timestamp NULL DEFAULT NULL COMMENT '创建时间 show1 show2 nameShow',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=utf8 COMMENT='公告信息';
/*Data for the table `news` */
insert into `news`(`id`,`news_name`,`news_types`,`news_photo`,`insert_time`,`news_content`,`create_time`) values (1,'公告标题1',1,'upload/news1.jpg','2023-03-21 10:29:31','公告详情1','2023-03-21 10:29:31'),(2,'公告标题2',1,'upload/news2.jpg','2023-03-21 10:29:31','公告详情2','2023-03-21 10:29:31'),(3,'公告标题3',1,'upload/news3.jpg','2023-03-21 10:29:31','公告详情3','2023-03-21 10:29:31'),(4,'公告标题4',2,'upload/news4.jpg','2023-03-21 10:29:31','公告详情4','2023-03-21 10:29:31'),(5,'公告标题5',1,'upload/news5.jpg','2023-03-21 10:29:31','公告详情5','2023-03-21 10:29:31'),(6,'公告标题6',1,'upload/news6.jpg','2023-03-21 10:29:31','公告详情6','2023-03-21 10:29:31'),(7,'公告标题7',2,'upload/news7.jpg','2023-03-21 10:29:31','公告详情7','2023-03-21 10:29:31'),(8,'公告标题8',1,'upload/news8.jpg','2023-03-21 10:29:31','公告详情8','2023-03-21 10:29:31'),(9,'公告标题9',1,'upload/news9.jpg','2023-03-21 10:29:31','公告详情9','2023-03-21 10:29:31'),(10,'公告标题10',2,'upload/news10.jpg','2023-03-21 10:29:31','公告详情10','2023-03-21 10:29:31'),(11,'公告标题11',1,'upload/news11.jpg','2023-03-21 10:29:31','公告详情11','2023-03-21 10:29:31'),(12,'公告标题12',1,'upload/news12.jpg','2023-03-21 10:29:31','公告详情12','2023-03-21 10:29:31'),(13,'公告标题13',2,'upload/news13.jpg','2023-03-21 10:29:31','公告详情13','2023-03-21 10:29:31'),(14,'公告标题14',2,'upload/news14.jpg','2023-03-21 10:29:31','公告详情14','2023-03-21 10:29:31');
/*Table structure for table `token` */
DROP TABLE IF EXISTS `token`;
CREATE TABLE `token` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
`userid` bigint(20) NOT NULL COMMENT '用户id',
`username` varchar(100) NOT NULL COMMENT '用户名',
`tablename` varchar(100) DEFAULT NULL COMMENT '表名',
`role` varchar(100) DEFAULT NULL COMMENT '角色',
`token` varchar(200) NOT NULL COMMENT '密码',
`addtime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '新增时间',
`expiratedtime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '过期时间',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COMMENT='token表';
/*Data for the table `token` */
insert into `token`(`id`,`userid`,`username`,`tablename`,`role`,`token`,`addtime`,`expiratedtime`) values (1,1,'admin','users','管理员','jjhb31mjf6ha4fkt8dfqn26fjju5jkb5','2023-03-21 10:33:32','2023-03-21 11:56:56'),(2,1,'a1','yonghu','用户','8erk329bwmbg8dymjfm5us2ckyib4yny','2023-03-21 10:34:45','2023-03-21 11:55:03');
/*Table structure for table `users` */
DROP TABLE IF EXISTS `users`;
CREATE TABLE `users` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
`username` varchar(100) NOT NULL COMMENT '用户名',
`password` varchar(100) NOT NULL COMMENT '密码',
`role` varchar(100) DEFAULT '管理员' COMMENT '角色',
`addtime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '新增时间',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COMMENT='管理员';
/*Data for the table `users` */
insert into `users`(`id`,`username`,`password`,`role`,`addtime`) values (1,'admin','admin','管理员','2023-03-21 10:29:19');
/*Table structure for table `wuzi` */
DROP TABLE IF EXISTS `wuzi`;
CREATE TABLE `wuzi` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键 ',
`wuzi_uuid_number` varchar(200) DEFAULT NULL COMMENT '物资编号',
`wuzi_name` varchar(200) DEFAULT NULL COMMENT '物资名称 Search111 ',
`wuzi_photo` varchar(200) DEFAULT NULL COMMENT '物资照片',
`wuzi_types` int(11) DEFAULT NULL COMMENT '物资类型 Search111',
`wuzi_kucun_number` int(11) DEFAULT NULL COMMENT '物资库存',
`wuzi_old_money` decimal(10,2) DEFAULT NULL COMMENT '原价 ',
`wuzi_new_money` decimal(10,2) DEFAULT NULL COMMENT '现价',
`wuzi_clicknum` int(11) DEFAULT NULL COMMENT '物资热度',
`wuzi_content` longtext COMMENT '物资介绍 ',
`shangxia_types` int(11) DEFAULT NULL COMMENT '是否上架 ',
`wuzi_delete` int(11) DEFAULT NULL COMMENT '逻辑删除',
`insert_time` timestamp NULL DEFAULT NULL COMMENT '录入时间',
`create_time` timestamp NULL DEFAULT NULL COMMENT '创建时间 show1 show2 photoShow',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=utf8 COMMENT='物资';
/*Data for the table `wuzi` */
insert into `wuzi`(`id`,`wuzi_uuid_number`,`wuzi_name`,`wuzi_photo`,`wuzi_types`,`wuzi_kucun_number`,`wuzi_old_money`,`wuzi_new_money`,`wuzi_clicknum`,`wuzi_content`,`shangxia_types`,`wuzi_delete`,`insert_time`,`create_time`) values (1,'1679365771292','物资名称1','upload/wuzi1.jpg',1,101,'514.91','89.31',120,'物资介绍1',1,1,'2023-03-21 10:29:31','2023-03-21 10:29:31'),(2,'1679365771360','物资名称2','upload/wuzi2.jpg',3,102,'550.38','228.32',16,'物资介绍2',1,1,'2023-03-21 10:29:31','2023-03-21 10:29:31'),(3,'1679365771311','物资名称3','upload/wuzi3.jpg',2,103,'782.00','206.73',212,'物资介绍3',1,1,'2023-03-21 10:29:31','2023-03-21 10:29:31'),(4,'1679365771283','物资名称4','upload/wuzi4.jpg',2,104,'585.60','163.70',325,'物资介绍4',1,1,'2023-03-21 10:29:31','2023-03-21 10:29:31'),(5,'1679365771320','物资名称5','upload/wuzi5.jpg',1,105,'999.73','370.18',333,'物资介绍5',1,1,'2023-03-21 10:29:31','2023-03-21 10:29:31'),(6,'1679365771351','物资名称6','upload/wuzi6.jpg',2,106,'589.15','101.18',336,'物资介绍6',1,1,'2023-03-21 10:29:31','2023-03-21 10:29:31'),(7,'1679365771283','物资名称7','upload/wuzi7.jpg',1,107,'693.98','245.87',281,'物资介绍7',1,1,'2023-03-21 10:29:31','2023-03-21 10:29:31'),(8,'1679365771328','物资名称8','upload/wuzi8.jpg',2,108,'712.87','255.94',74,'物资介绍8',1,1,'2023-03-21 10:29:31','2023-03-21 10:29:31'),(9,'1679365771353','物资名称9','upload/wuzi9.jpg',3,109,'797.51','10.87',327,'物资介绍9',1,1,'2023-03-21 10:29:31','2023-03-21 10:29:31'),(10,'1679365771325','物资名称10','upload/wuzi10.jpg',2,1010,'824.80','325.91',307,'物资介绍10',1,1,'2023-03-21 10:29:31','2023-03-21 10:29:31'),(11,'1679365771347','物资名称11','upload/wuzi11.jpg',1,1011,'587.45','150.93',213,'物资介绍11',1,1,'2023-03-21 10:29:31','2023-03-21 10:29:31'),(12,'1679365771317','物资名称12','upload/wuzi12.jpg',1,1010,'954.64','63.52',486,'物资介绍12',1,1,'2023-03-21 10:29:31','2023-03-21 10:29:31'),(13,'1679365771282','物资名称13','upload/wuzi13.jpg',1,1013,'707.69','314.98',355,'物资介绍13',1,1,'2023-03-21 10:29:31','2023-03-21 10:29:31'),(14,'1679365771302','物资名称14','upload/wuzi14.jpg',1,1014,'674.28','290.95',135,'物资介绍14',2,1,'2023-03-21 10:29:31','2023-03-21 10:29:31');
/*Table structure for table `wuzi_collection` */
DROP TABLE IF EXISTS `wuzi_collection`;
CREATE TABLE `wuzi_collection` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键',
`wuzi_id` int(11) DEFAULT NULL COMMENT '物资',
`yonghu_id` int(11) DEFAULT NULL COMMENT '用户',
`wuzi_collection_types` int(11) DEFAULT NULL COMMENT '类型',
`insert_time` timestamp NULL DEFAULT NULL COMMENT '收藏时间',
`create_time` timestamp NULL DEFAULT NULL COMMENT '创建时间 show3 photoShow',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=utf8 COMMENT='物资收藏';
/*Data for the table `wuzi_collection` */
insert into `wuzi_collection`(`id`,`wuzi_id`,`yonghu_id`,`wuzi_collection_types`,`insert_time`,`create_time`) values (1,1,3,1,'2023-03-21 10:29:31','2023-03-21 10:29:31'),(2,2,2,1,'2023-03-21 10:29:31','2023-03-21 10:29:31'),(3,3,3,1,'2023-03-21 10:29:31','2023-03-21 10:29:31'),(4,4,1,1,'2023-03-21 10:29:31','2023-03-21 10:29:31'),(5,5,3,1,'2023-03-21 10:29:31','2023-03-21 10:29:31'),(6,6,2,1,'2023-03-21 10:29:31','2023-03-21 10:29:31'),(7,7,2,1,'2023-03-21 10:29:31','2023-03-21 10:29:31'),(8,8,3,1,'2023-03-21 10:29:31','2023-03-21 10:29:31'),(9,9,2,1,'2023-03-21 10:29:31','2023-03-21 10:29:31'),(10,10,1,1,'2023-03-21 10:29:31','2023-03-21 10:29:31'),(11,11,3,1,'2023-03-21 10:29:31','2023-03-21 10:29:31'),(12,12,3,1,'2023-03-21 10:29:31','2023-03-21 10:29:31'),(13,13,2,1,'2023-03-21 10:29:31','2023-03-21 10:29:31'),(14,14,3,1,'2023-03-21 10:29:31','2023-03-21 10:29:31');
/*Table structure for table `wuzi_order` */
DROP TABLE IF EXISTS `wuzi_order`;
CREATE TABLE `wuzi_order` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键',
`wuzi_order_uuid_number` varchar(200) DEFAULT NULL COMMENT '订单号 Search111 ',
`address_id` int(11) DEFAULT NULL COMMENT '收货地址 ',
`wuzi_id` int(11) DEFAULT NULL COMMENT '物资',
`yonghu_id` int(11) DEFAULT NULL COMMENT '用户',
`buy_number` int(11) DEFAULT NULL COMMENT '购买数量',
`wuzi_order_true_price` decimal(10,2) DEFAULT NULL COMMENT '实付价格',
`wuzi_order_types` int(11) DEFAULT NULL COMMENT '订单类型 Search111 ',
`wuzi_order_payment_types` int(11) DEFAULT NULL COMMENT '支付类型',
`insert_time` timestamp NULL DEFAULT NULL COMMENT '订单创建时间',
`create_time` timestamp NULL DEFAULT NULL COMMENT '创建时间 show3 listShow',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COMMENT='物资订单';
/*Data for the table `wuzi_order` */
insert into `wuzi_order`(`id`,`wuzi_order_uuid_number`,`address_id`,`wuzi_id`,`yonghu_id`,`buy_number`,`wuzi_order_true_price`,`wuzi_order_types`,`wuzi_order_payment_types`,`insert_time`,`create_time`) values (1,'1679367307706',12,12,1,2,'127.04',104,1,'2023-03-21 10:55:08','2023-03-21 10:55:08');
/*Table structure for table `wuzijuanzeng` */
DROP TABLE IF EXISTS `wuzijuanzeng`;
CREATE TABLE `wuzijuanzeng` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键',
`wuzijuanzeng_name` varchar(200) DEFAULT NULL COMMENT '捐赠标题 Search111 ',
`wuzijuanzeng_types` int(11) DEFAULT NULL COMMENT '捐赠类型 Search111 ',
`yonghu_id` int(20) NOT NULL COMMENT '捐赠用户',
`wuzijuanzeng_numb` int(11) DEFAULT NULL COMMENT '捐赠数量',
`insert_time` timestamp NULL DEFAULT NULL COMMENT '添加时间',
`wuzijuanzeng_content` longtext COMMENT '捐赠详情',
`create_time` timestamp NULL DEFAULT NULL COMMENT '创建时间 show3 listShow',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=17 DEFAULT CHARSET=utf8 COMMENT='物资捐赠';
/*Data for the table `wuzijuanzeng` */
insert into `wuzijuanzeng`(`id`,`wuzijuanzeng_name`,`wuzijuanzeng_types`,`yonghu_id`,`wuzijuanzeng_numb`,`insert_time`,`wuzijuanzeng_content`,`create_time`) values (1,'捐赠标题1',1,3,149,'2023-03-21 10:29:31','捐赠详情1','2023-03-21 10:29:31'),(2,'捐赠标题2',1,3,67,'2023-03-21 10:29:31','捐赠详情2','2023-03-21 10:29:31'),(3,'捐赠标题3',2,2,364,'2023-03-21 10:29:31','捐赠详情3','2023-03-21 10:29:31'),(4,'捐赠标题4',1,1,137,'2023-03-21 10:29:31','捐赠详情4','2023-03-21 10:29:31'),(5,'捐赠标题5',2,1,484,'2023-03-21 10:29:31','捐赠详情5','2023-03-21 10:29:31'),(6,'捐赠标题6',2,2,60,'2023-03-21 10:29:31','捐赠详情6','2023-03-21 10:29:31'),(7,'捐赠标题7',2,3,85,'2023-03-21 10:29:31','捐赠详情7','2023-03-21 10:29:31'),(8,'捐赠标题8',2,1,201,'2023-03-21 10:29:31','捐赠详情8','2023-03-21 10:29:31'),(9,'捐赠标题9',2,2,500,'2023-03-21 10:29:31','捐赠详情9','2023-03-21 10:29:31'),(10,'捐赠标题10',1,3,470,'2023-03-21 10:29:31','捐赠详情10','2023-03-21 10:29:31'),(11,'捐赠标题11',1,3,87,'2023-03-21 10:29:31','捐赠详情11','2023-03-21 10:29:31'),(12,'捐赠标题12',2,1,485,'2023-03-21 10:29:31','捐赠详情12','2023-03-21 10:29:31'),(13,'捐赠标题13',2,1,273,'2023-03-21 10:29:31','捐赠详情13','2023-03-21 10:29:31'),(14,'捐赠标题14',1,1,399,'2023-03-21 10:29:31','捐赠详情14','2023-03-21 10:29:31'),(16,'xxx捐赠蔬菜1吨',2,1,1,'2023-03-21 10:56:08','1','2023-03-21 10:56:08');
/*Table structure for table `yonghu` */
DROP TABLE IF EXISTS `yonghu`;
CREATE TABLE `yonghu` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键',
`username` varchar(200) DEFAULT NULL COMMENT '账户',
`password` varchar(200) DEFAULT NULL COMMENT '密码',
`yonghu_name` varchar(200) DEFAULT NULL COMMENT '用户姓名 Search111 ',
`yonghu_phone` varchar(200) DEFAULT NULL COMMENT '联系方式',
`yonghu_id_number` varchar(200) DEFAULT NULL COMMENT '身份证号',
`yonghu_photo` varchar(200) DEFAULT NULL COMMENT '用户头像',
`sex_types` int(11) DEFAULT NULL COMMENT '性别 Search111',
`yonghu_email` varchar(200) DEFAULT NULL COMMENT '电子邮箱',
`new_money` decimal(10,2) DEFAULT NULL COMMENT '余额 ',
`create_time` timestamp NULL DEFAULT NULL COMMENT '创建时间',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COMMENT='用户';
/*Data for the table `yonghu` */
insert into `yonghu`(`id`,`username`,`password`,`yonghu_name`,`yonghu_phone`,`yonghu_id_number`,`yonghu_photo`,`sex_types`,`yonghu_email`,`new_money`,`create_time`) values (1,'a1','123456','用户姓名1','17703786901','410224199010102001','upload/yonghu1.jpg',2,'1@qq.com','100060.66','2023-03-21 10:29:31'),(2,'a2','123456','用户姓名2','17703786902','410224199010102002','upload/yonghu2.jpg',2,'2@qq.com','215.00','2023-03-21 10:29:31'),(3,'a3','123456','用户姓名3','17703786903','410224199010102003','upload/yonghu3.jpg',2,'3@qq.com','108.99','2023-03-21 10:29:31');
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
5、关键代码
5.1 物资管理Controller模块
package com.controller;
import java.io.File;
import java.math.BigDecimal;
import java.net.URL;
import java.text.SimpleDateFormat;
import com.alibaba.fastjson.JSONObject;
import java.util.*;
import org.springframework.beans.BeanUtils;
import javax.servlet.http.HttpServletRequest;
import org.springframework.web.context.ContextLoader;
import javax.servlet.ServletContext;
import com.service.TokenService;
import com.utils.*;
import java.lang.reflect.InvocationTargetException;
import com.service.DictionaryService;
import org.apache.commons.lang3.StringUtils;
import com.annotation.IgnoreAuth;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.entity.*;
import com.entity.view.*;
import com.service.*;
import com.utils.PageUtils;
import com.utils.R;
import com.alibaba.fastjson.*;
/**
* 物资
* 后端接口
* @author
* @email
*/
@RestController
@Controller
@RequestMapping("/wuzi")
public class WuziController {
private static final Logger logger = LoggerFactory.getLogger(WuziController.class);
private static final String TABLE_NAME = "wuzi";
@Autowired
private WuziService wuziService;
@Autowired
private TokenService tokenService;
@Autowired
private AddressService addressService;//收货地址
@Autowired
private DictionaryService dictionaryService;//字典
@Autowired
private ForumService forumService;//论坛
@Autowired
private LiuyanService liuyanService;//求助留言板
@Autowired
private NewsService newsService;//公告信息
@Autowired
private WuziCollectionService wuziCollectionService;//物资收藏
@Autowired
private WuziOrderService wuziOrderService;//物资订单
@Autowired
private WuzijuanzengService wuzijuanzengService;//物资捐赠
@Autowired
private YonghuService yonghuService;//用户
@Autowired
private UsersService usersService;//管理员
/**
* 后端列表
*/
@RequestMapping("/page")
public R page(@RequestParam Map<String, Object> params, HttpServletRequest request){
logger.debug("page方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params));
String role = String.valueOf(request.getSession().getAttribute("role"));
if(false)
return R.error(511,"永不会进入");
else if("用户".equals(role))
params.put("yonghuId",request.getSession().getAttribute("userId"));
params.put("wuziDeleteStart",1);params.put("wuziDeleteEnd",1);
CommonUtil.checkMap(params);
PageUtils page = wuziService.queryPage(params);
//字典表数据转换
List<WuziView> list =(List<WuziView>)page.getList();
for(WuziView c:list){
//修改对应字典表字段
dictionaryService.dictionaryConvert(c, request);
}
return R.ok().put("data", page);
}
/**
* 后端详情
*/
@RequestMapping("/info/{id}")
public R info(@PathVariable("id") Long id, HttpServletRequest request){
logger.debug("info方法:,,Controller:{},,id:{}",this.getClass().getName(),id);
WuziEntity wuzi = wuziService.selectById(id);
if(wuzi !=null){
//entity转view
WuziView view = new WuziView();
BeanUtils.copyProperties( wuzi , view );//把实体数据重构到view中
//修改对应字典表字段
dictionaryService.dictionaryConvert(view, request);
return R.ok().put("data", view);
}else {
return R.error(511,"查不到数据");
}
}
/**
* 后端保存
*/
@RequestMapping("/save")
public R save(@RequestBody WuziEntity wuzi, HttpServletRequest request){
logger.debug("save方法:,,Controller:{},,wuzi:{}",this.getClass().getName(),wuzi.toString());
String role = String.valueOf(request.getSession().getAttribute("role"));
if(false)
return R.error(511,"永远不会进入");
Wrapper<WuziEntity> queryWrapper = new EntityWrapper<WuziEntity>()
.eq("wuzi_name", wuzi.getWuziName())
.eq("wuzi_types", wuzi.getWuziTypes())
.eq("wuzi_kucun_number", wuzi.getWuziKucunNumber())
.eq("shangxia_types", wuzi.getShangxiaTypes())
.eq("wuzi_delete", wuzi.getWuziDelete())
;
logger.info("sql语句:"+queryWrapper.getSqlSegment());
WuziEntity wuziEntity = wuziService.selectOne(queryWrapper);
if(wuziEntity==null){
wuzi.setWuziClicknum(1);
wuzi.setShangxiaTypes(1);
wuzi.setWuziDelete(1);
wuzi.setInsertTime(new Date());
wuzi.setCreateTime(new Date());
wuziService.insert(wuzi);
return R.ok();
}else {
return R.error(511,"表中有相同数据");
}
}
/**
* 后端修改
*/
@RequestMapping("/update")
public R update(@RequestBody WuziEntity wuzi, HttpServletRequest request) throws NoSuchFieldException, ClassNotFoundException, IllegalAccessException, InstantiationException {
logger.debug("update方法:,,Controller:{},,wuzi:{}",this.getClass().getName(),wuzi.toString());
WuziEntity oldWuziEntity = wuziService.selectById(wuzi.getId());//查询原先数据
String role = String.valueOf(request.getSession().getAttribute("role"));
// if(false)
// return R.error(511,"永远不会进入");
if("".equals(wuzi.getWuziPhoto()) || "null".equals(wuzi.getWuziPhoto())){
wuzi.setWuziPhoto(null);
}
wuziService.updateById(wuzi);//根据id更新
return R.ok();
}
/**
* 删除
*/
@RequestMapping("/delete")
public R delete(@RequestBody Integer[] ids, HttpServletRequest request){
logger.debug("delete:,,Controller:{},,ids:{}",this.getClass().getName(),ids.toString());
List<WuziEntity> oldWuziList =wuziService.selectBatchIds(Arrays.asList(ids));//要删除的数据
ArrayList<WuziEntity> list = new ArrayList<>();
for(Integer id:ids){
WuziEntity wuziEntity = new WuziEntity();
wuziEntity.setId(id);
wuziEntity.setWuziDelete(2);
list.add(wuziEntity);
}
if(list != null && list.size() >0){
wuziService.updateBatchById(list);
}
return R.ok();
}
/**
* 批量上传
*/
@RequestMapping("/batchInsert")
public R save( String fileName, HttpServletRequest request){
logger.debug("batchInsert方法:,,Controller:{},,fileName:{}",this.getClass().getName(),fileName);
Integer yonghuId = Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId")));
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
List<WuziEntity> wuziList = new ArrayList<>();//上传的东西
Map<String, List<String>> seachFields= new HashMap<>();//要查询的字段
Date date = new Date();
int lastIndexOf = fileName.lastIndexOf(".");
if(lastIndexOf == -1){
return R.error(511,"该文件没有后缀");
}else{
String suffix = fileName.substring(lastIndexOf);
if(!".xls".equals(suffix)){
return R.error(511,"只支持后缀为xls的excel文件");
}else{
URL resource = this.getClass().getClassLoader().getResource("static/upload/" + fileName);//获取文件路径
File file = new File(resource.getFile());
if(!file.exists()){
return R.error(511,"找不到上传文件,请联系管理员");
}else{
List<List<String>> dataList = PoiUtil.poiImport(file.getPath());//读取xls文件
dataList.remove(0);//删除第一行,因为第一行是提示
for(List<String> data:dataList){
//循环
WuziEntity wuziEntity = new WuziEntity();
// wuziEntity.setWuziUuidNumber(data.get(0)); //物资编号 要改的
// wuziEntity.setWuziName(data.get(0)); //物资名称 要改的
// wuziEntity.setWuziPhoto("");//详情和图片
// wuziEntity.setWuziTypes(Integer.valueOf(data.get(0))); //物资类型 要改的
// wuziEntity.setWuziKucunNumber(Integer.valueOf(data.get(0))); //物资库存 要改的
// wuziEntity.setWuziOldMoney(data.get(0)); //原价 要改的
// wuziEntity.setWuziNewMoney(data.get(0)); //现价 要改的
// wuziEntity.setWuziClicknum(Integer.valueOf(data.get(0))); //物资热度 要改的
// wuziEntity.setWuziContent("");//详情和图片
// wuziEntity.setShangxiaTypes(Integer.valueOf(data.get(0))); //是否上架 要改的
// wuziEntity.setWuziDelete(1);//逻辑删除字段
// wuziEntity.setInsertTime(date);//时间
// wuziEntity.setCreateTime(date);//时间
wuziList.add(wuziEntity);
//把要查询是否重复的字段放入map中
//物资编号
if(seachFields.containsKey("wuziUuidNumber")){
List<String> wuziUuidNumber = seachFields.get("wuziUuidNumber");
wuziUuidNumber.add(data.get(0));//要改的
}else{
List<String> wuziUuidNumber = new ArrayList<>();
wuziUuidNumber.add(data.get(0));//要改的
seachFields.put("wuziUuidNumber",wuziUuidNumber);
}
}
//查询是否重复
//物资编号
List<WuziEntity> wuziEntities_wuziUuidNumber = wuziService.selectList(new EntityWrapper<WuziEntity>().in("wuzi_uuid_number", seachFields.get("wuziUuidNumber")).eq("wuzi_delete", 1));
if(wuziEntities_wuziUuidNumber.size() >0 ){
ArrayList<String> repeatFields = new ArrayList<>();
for(WuziEntity s:wuziEntities_wuziUuidNumber){
repeatFields.add(s.getWuziUuidNumber());
}
return R.error(511,"数据库的该表中的 [物资编号] 字段已经存在 存在数据为:"+repeatFields.toString());
}
wuziService.insertBatch(wuziList);
return R.ok();
}
}
}
}catch (Exception e){
e.printStackTrace();
return R.error(511,"批量插入数据异常,请联系管理员");
}
}
/**
* 个性推荐
*/
@IgnoreAuth
@RequestMapping("/gexingtuijian")
public R gexingtuijian(@RequestParam Map<String, Object> params, HttpServletRequest request){
logger.debug("gexingtuijian方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params));
CommonUtil.checkMap(params);
List<WuziView> returnWuziViewList = new ArrayList<>();
//查询订单
Map<String, Object> params1 = new HashMap<>(params);params1.put("sort","id");params1.put("yonghuId",request.getSession().getAttribute("userId"));
PageUtils pageUtils = wuziOrderService.queryPage(params1);
List<WuziOrderView> orderViewsList =(List<WuziOrderView>)pageUtils.getList();
Map<Integer,Integer> typeMap=new HashMap<>();//购买的类型list
for(WuziOrderView orderView:orderViewsList){
Integer wuziTypes = orderView.getWuziTypes();
if(typeMap.containsKey(wuziTypes)){
typeMap.put(wuziTypes,typeMap.get(wuziTypes)+1);
}else{
typeMap.put(wuziTypes,1);
}
}
List<Integer> typeList = new ArrayList<>();//排序后的有序的类型 按最多到最少
typeMap.entrySet().stream().sorted((o1, o2) -> o2.getValue() - o1.getValue()).forEach(e -> typeList.add(e.getKey()));//排序
Integer limit = Integer.valueOf(String.valueOf(params.get("limit")));
for(Integer type:typeList){
Map<String, Object> params2 = new HashMap<>(params);params2.put("wuziTypes",type);
PageUtils pageUtils1 = wuziService.queryPage(params2);
List<WuziView> wuziViewList =(List<WuziView>)pageUtils1.getList();
returnWuziViewList.addAll(wuziViewList);
if(returnWuziViewList.size()>= limit) break;//返回的推荐数量大于要的数量 跳出循环
}
//正常查询出来商品,用于补全推荐缺少的数据
PageUtils page = wuziService.queryPage(params);
if(returnWuziViewList.size()<limit){//返回数量还是小于要求数量
int toAddNum = limit - returnWuziViewList.size();//要添加的数量
List<WuziView> wuziViewList =(List<WuziView>)page.getList();
for(WuziView wuziView:wuziViewList){
Boolean addFlag = true;
for(WuziView returnWuziView:returnWuziViewList){
if(returnWuziView.getId().intValue() ==wuziView.getId().intValue()) addFlag=false;//返回的数据中已存在此商品
}
if(addFlag){
toAddNum=toAddNum-1;
returnWuziViewList.add(wuziView);
if(toAddNum==0) break;//够数量了
}
}
}else {
returnWuziViewList = returnWuziViewList.subList(0, limit);
}
for(WuziView c:returnWuziViewList)
dictionaryService.dictionaryConvert(c, request);
page.setList(returnWuziViewList);
return R.ok().put("data", page);
}
/**
* 前端列表
*/
@IgnoreAuth
@RequestMapping("/list")
public R list(@RequestParam Map<String, Object> params, HttpServletRequest request){
logger.debug("list方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params));
CommonUtil.checkMap(params);
PageUtils page = wuziService.queryPage(params);
//字典表数据转换
List<WuziView> list =(List<WuziView>)page.getList();
for(WuziView c:list)
dictionaryService.dictionaryConvert(c, request); //修改对应字典表字段
return R.ok().put("data", page);
}
/**
* 前端详情
*/
@RequestMapping("/detail/{id}")
public R detail(@PathVariable("id") Long id, HttpServletRequest request){
logger.debug("detail方法:,,Controller:{},,id:{}",this.getClass().getName(),id);
WuziEntity wuzi = wuziService.selectById(id);
if(wuzi !=null){
//点击数量加1
wuzi.setWuziClicknum(wuzi.getWuziClicknum()+1);
wuziService.updateById(wuzi);
//entity转view
WuziView view = new WuziView();
BeanUtils.copyProperties( wuzi , view );//把实体数据重构到view中
//修改对应字典表字段
dictionaryService.dictionaryConvert(view, request);
return R.ok().put("data", view);
}else {
return R.error(511,"查不到数据");
}
}
/**
* 前端保存
*/
@RequestMapping("/add")
public R add(@RequestBody WuziEntity wuzi, HttpServletRequest request){
logger.debug("add方法:,,Controller:{},,wuzi:{}",this.getClass().getName(),wuzi.toString());
Wrapper<WuziEntity> queryWrapper = new EntityWrapper<WuziEntity>()
.eq("wuzi_uuid_number", wuzi.getWuziUuidNumber())
.eq("wuzi_name", wuzi.getWuziName())
.eq("wuzi_types", wuzi.getWuziTypes())
.eq("wuzi_kucun_number", wuzi.getWuziKucunNumber())
.eq("wuzi_clicknum", wuzi.getWuziClicknum())
.eq("shangxia_types", wuzi.getShangxiaTypes())
.eq("wuzi_delete", wuzi.getWuziDelete())
// .notIn("wuzi_types", new Integer[]{102})
;
logger.info("sql语句:"+queryWrapper.getSqlSegment());
WuziEntity wuziEntity = wuziService.selectOne(queryWrapper);
if(wuziEntity==null){
wuzi.setWuziClicknum(1);
wuzi.setWuziDelete(1);
wuzi.setInsertTime(new Date());
wuzi.setCreateTime(new Date());
wuziService.insert(wuzi);
return R.ok();
}else {
return R.error(511,"表中有相同数据");
}
}
}
5.2 物资管理Service模块
package com.service;
import com.baomidou.mybatisplus.service.IService;
import com.utils.PageUtils;
import com.entity.WuziCollectionEntity;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.springframework.lang.Nullable;
import java.util.List;
/**
* 物资收藏 服务类
*/
public interface WuziCollectionService extends IService<WuziCollectionEntity> {
/**
* @param params 查询参数
* @return 带分页的查询出来的数据
*/
PageUtils queryPage(Map<String, Object> params);
}
5.3 物资管理ServiceImpl模块
package com.service.impl;
import com.utils.StringUtil;
import com.service.DictionaryService;
import com.utils.ClazzDiff;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.lang.reflect.Field;
import java.util.*;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.transaction.annotation.Transactional;
import com.utils.PageUtils;
import com.utils.Query;
import org.springframework.web.context.ContextLoader;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import com.dao.WuziDao;
import com.entity.WuziEntity;
import com.service.WuziService;
import com.entity.view.WuziView;
/**
* 物资 服务实现类
*/
@Service("wuziService")
@Transactional
public class WuziServiceImpl extends ServiceImpl<WuziDao, WuziEntity> implements WuziService {
@Override
public PageUtils queryPage(Map<String,Object> params) {
Page<WuziView> page =new Query<WuziView>(params).getPage();
page.setRecords(baseMapper.selectListView(page,params));
return new PageUtils(page);
}
}
5.4 物资管理Dao模块
package com.dao;
import com.entity.WuziEntity;
import com.baomidou.mybatisplus.mapper.BaseMapper;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.plugins.pagination.Pagination;
import org.apache.ibatis.annotations.Param;
import com.entity.view.WuziView;
/**
* 物资 Dao 接口
*
* @author
*/
public interface WuziDao extends BaseMapper<WuziEntity> {
List<WuziView> selectListView(Pagination page,@Param("params")Map<String,Object> params);
}
6、论文目录结构
7、源码获取
感谢大家的阅读,如有不懂的问题可以评论区交流或私聊!
喜欢文章可以点赞、收藏、关注、评论啦
→获取源码请私信←