commit
8b5ecd6f27
@ -0,0 +1,37 @@
|
||||
HELP.md
|
||||
target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
!**/src/main/**/target/
|
||||
!**/src/test/**/target
|
||||
/.mvn/
|
||||
|
||||
### STS ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
*.log
|
||||
*.jar
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
build/
|
||||
!**/src/main/**/build/
|
||||
!**/src/test/**/build/
|
||||
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
@ -0,0 +1,154 @@
|
||||
/*
|
||||
Navicat Premium Data Transfer
|
||||
|
||||
Source Server : local
|
||||
Source Server Type : MySQL
|
||||
Source Server Version : 80029
|
||||
Source Host : localhost:3306
|
||||
Source Schema : DB_flower
|
||||
|
||||
Target Server Type : MySQL
|
||||
Target Server Version : 80029
|
||||
File Encoding : 65001
|
||||
|
||||
Date: 26/01/2024 15:29:41
|
||||
*/
|
||||
|
||||
SET NAMES utf8mb4;
|
||||
SET FOREIGN_KEY_CHECKS = 0;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for carts
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `carts`;
|
||||
CREATE TABLE `carts` (
|
||||
`id` int NOT NULL AUTO_INCREMENT,
|
||||
`fid` int DEFAULT NULL,
|
||||
`flower` varchar(255) DEFAULT NULL,
|
||||
`amount` int DEFAULT NULL,
|
||||
`price` float DEFAULT NULL,
|
||||
`uid` int DEFAULT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `flower` (`flower`),
|
||||
KEY `uid` (`uid`),
|
||||
KEY `fk2` (`fid`),
|
||||
CONSTRAINT `carts_ibfk_2` FOREIGN KEY (`uid`) REFERENCES `users` (`id`),
|
||||
CONSTRAINT `fk2` FOREIGN KEY (`fid`) REFERENCES `flowers` (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=35 DEFAULT CHARSET=utf8mb3;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of carts
|
||||
-- ----------------------------
|
||||
BEGIN;
|
||||
INSERT INTO `carts` VALUES (32, 2, '粉色玫瑰花', 1, NULL, 10);
|
||||
INSERT INTO `carts` VALUES (33, 4, '金枝玉叶玫瑰', 3, NULL, 10);
|
||||
INSERT INTO `carts` VALUES (34, 1, '杭州水果捞', 1, NULL, 10);
|
||||
COMMIT;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for flowers
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `flowers`;
|
||||
CREATE TABLE `flowers` (
|
||||
`id` int NOT NULL AUTO_INCREMENT,
|
||||
`name` varchar(255) DEFAULT NULL,
|
||||
`species_name` varchar(255) DEFAULT NULL,
|
||||
`price` float DEFAULT NULL,
|
||||
`detail` varchar(255) DEFAULT NULL,
|
||||
`img_guid` varchar(255) DEFAULT NULL,
|
||||
`state` int DEFAULT '1' COMMENT '商品状态',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `name` (`name`),
|
||||
KEY `species_name` (`species_name`),
|
||||
CONSTRAINT `flowers_ibfk_1` FOREIGN KEY (`species_name`) REFERENCES `species` (`species_name`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8mb3;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of flowers
|
||||
-- ----------------------------
|
||||
BEGIN;
|
||||
INSERT INTO `flowers` VALUES (1, '杭州水果捞', '春日', 10, '杭州水果捞', 'fe71ee4538644b4da67b046d3a6825a8.jpg', 1);
|
||||
INSERT INTO `flowers` VALUES (2, '粉色玫瑰花', '夏日', 199, '粉色玫瑰花,送爱人~', '67975badf69646c0a70e8154208c7acd.jpg', 1);
|
||||
INSERT INTO `flowers` VALUES (3, '牡丹', '夏日', 299, '国花,价格优惠', 'hehua.jpg', 1);
|
||||
INSERT INTO `flowers` VALUES (4, '金枝玉叶玫瑰', '秋日', 999.99, '金枝玉叶玫瑰', '8d59b8723ad6409ab3b10847f86ef196.jpg', 1);
|
||||
INSERT INTO `flowers` VALUES (5, '紫色小雏菊', '夏日', 188, '紫色小雏菊~', 'eff301d8ca194fb99639ebe4f1d328b9.jpg', 1);
|
||||
INSERT INTO `flowers` VALUES (6, NULL, NULL, NULL, NULL, '', 1);
|
||||
INSERT INTO `flowers` VALUES (7, '粉百合', '冬日', 10000, '粉百合', '6d901436d6e84160b04de4cafa79a611.jpg', 1);
|
||||
COMMIT;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for orders
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `orders`;
|
||||
CREATE TABLE `orders` (
|
||||
`id` int NOT NULL AUTO_INCREMENT,
|
||||
`order_guid` varchar(255) DEFAULT NULL,
|
||||
`flower` varchar(255) DEFAULT NULL,
|
||||
`amount` int DEFAULT NULL,
|
||||
`price` float DEFAULT NULL,
|
||||
`state` int DEFAULT NULL,
|
||||
`uid` int DEFAULT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `flower` (`flower`),
|
||||
KEY `uid` (`uid`),
|
||||
CONSTRAINT `orders_ibfk_2` FOREIGN KEY (`uid`) REFERENCES `users` (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=29 DEFAULT CHARSET=utf8mb3;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of orders
|
||||
-- ----------------------------
|
||||
BEGIN;
|
||||
INSERT INTO `orders` VALUES (27, NULL, '杭州水果捞', 3, 30, 0, 10);
|
||||
INSERT INTO `orders` VALUES (28, NULL, '金枝玉叶玫瑰', 1, 999.99, 0, 10);
|
||||
COMMIT;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for species
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `species`;
|
||||
CREATE TABLE `species` (
|
||||
`id` int NOT NULL AUTO_INCREMENT,
|
||||
`species_name` varchar(255) DEFAULT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `species` (`species_name`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=utf8mb3;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of species
|
||||
-- ----------------------------
|
||||
BEGIN;
|
||||
INSERT INTO `species` VALUES (8, NULL);
|
||||
INSERT INTO `species` VALUES (7, '冬日');
|
||||
INSERT INTO `species` VALUES (11, '友情花');
|
||||
INSERT INTO `species` VALUES (2, '夏日');
|
||||
INSERT INTO `species` VALUES (9, '情人花');
|
||||
INSERT INTO `species` VALUES (1, '春日');
|
||||
INSERT INTO `species` VALUES (3, '秋日');
|
||||
COMMIT;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for users
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `users`;
|
||||
CREATE TABLE `users` (
|
||||
`id` int NOT NULL AUTO_INCREMENT,
|
||||
`account` varchar(255) DEFAULT NULL,
|
||||
`name` varchar(255) DEFAULT NULL,
|
||||
`password` varchar(255) DEFAULT NULL,
|
||||
`phone` varchar(255) DEFAULT NULL,
|
||||
`address` varchar(255) DEFAULT NULL,
|
||||
`role` varchar(255) DEFAULT NULL COMMENT '角色',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `account` (`account`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb3;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of users
|
||||
-- ----------------------------
|
||||
BEGIN;
|
||||
INSERT INTO `users` VALUES (1, 'user2', 'user2', '123456', '13566662222', '北京市昌平区2号', 'user');
|
||||
INSERT INTO `users` VALUES (2, 'admin', '系统管理员', '123456', '123456', '上海市黄浦区南京西路8号', 'admin');
|
||||
INSERT INTO `users` VALUES (10, 'user', '杭州水果捞', '123456', '18679121111', '杭州余杭区', 'user');
|
||||
COMMIT;
|
||||
|
||||
SET FOREIGN_KEY_CHECKS = 1;
|
@ -0,0 +1,131 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.4.5</version>
|
||||
<relativePath/>
|
||||
</parent>
|
||||
|
||||
<groupId>com.shanzhu</groupId>
|
||||
<artifactId>flower-backend</artifactId>
|
||||
<version>1.0.0-RELEASE</version>
|
||||
|
||||
<name>flower-backend</name>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<description>花店商城后台</description>
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.10</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-jdbc</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mybatis.spring.boot</groupId>
|
||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||
<version>2.1.3</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>tk.mybatis</groupId>
|
||||
<artifactId>mapper-spring-boot-starter</artifactId>
|
||||
<version>2.0.4</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.junit.vintage</groupId>
|
||||
<artifactId>junit-vintage-engine</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter</artifactId>
|
||||
<version>5.4.2</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.sourceforge.nekohtml</groupId>
|
||||
<artifactId>nekohtml</artifactId>
|
||||
<version>1.9.22</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-pool2</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.poi</groupId>
|
||||
<artifactId>poi-ooxml</artifactId>
|
||||
<version>3.17</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger2</artifactId>
|
||||
<version>2.9.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger-ui</artifactId>
|
||||
<version>2.9.2</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
@ -0,0 +1,20 @@
|
||||
package com.shanzhu.flower.config;
|
||||
|
||||
/**
|
||||
* 常量
|
||||
* 图片静态文件路径
|
||||
*
|
||||
* @author: ShanZhu
|
||||
* @date: 2024-01-24
|
||||
*/
|
||||
public class Constant {
|
||||
|
||||
public static int PAGE_SIZE = 5;
|
||||
|
||||
// 商品展示
|
||||
public static int SHOW_PAGE_SIZE = 9;
|
||||
|
||||
public static String IMG_USE_PATH = "static/imgs/";
|
||||
|
||||
public static String DEFAULT_IMG = "img.jpg";
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
package com.shanzhu.flower.config;
|
||||
|
||||
/**
|
||||
* http状态消息
|
||||
*
|
||||
* @author: ShanZhu
|
||||
* @date: 2024-01-24
|
||||
*/
|
||||
public class HttpMsg {
|
||||
public static String ERROR_INPUT = "表单信息不正确";
|
||||
public static String ERROR_VERIFY = "用户名或密码错误";
|
||||
public static String ADD_USER_OK = "新建用户成功";
|
||||
public static String ADD_USER_FAILED = "新建用户失败,该账号已存在";
|
||||
public static String UPDATE_USER_OK = "修改用户信息成功";
|
||||
public static String UPDATE_USER_FAILED = "修改用户信息失败";
|
||||
public static String DELETE_USER_OK = "删除用户信息成功";
|
||||
public static String DELETE_USER_FAILED = "删除用户信息失败";
|
||||
|
||||
public static String DELETE_TYPE_OK = "删除类型成功";
|
||||
public static String DELETE_TYPE_FAILED = "有商品绑定此类型,删除类型失败";
|
||||
public static String UPDATE_TYPE_OK = "修改类型成功";
|
||||
public static String UPDATE_TYPE_FAILED = "有商品绑定此类型,修改类型失败";
|
||||
public static String ADD_TYPE_OK = "新建类型成功";
|
||||
public static String ADD_TYPE_FAILED = "新建类型失败,该类型名称已存在";
|
||||
|
||||
public static String DELETE_FLOWER_OK = "删除类型成功";
|
||||
public static String DELETE_FLOWER_FAILED = "有商品绑定此类型,删除类型失败";
|
||||
public static String UPDATE_FLOWER_OK = "修改类型成功";
|
||||
public static String UPDATE_FLOWER_FAILED = "有商品绑定此类型,修改类型失败";
|
||||
public static String ADD_FLOWER_OK = "新建类型成功";
|
||||
public static String ADD_FLOWER_FAILED = "新建类型失败,该类型名称已存在";
|
||||
|
||||
public static String NO_TYPE_NOW = "当前没有花朵种类,请先创建!";
|
||||
|
||||
public static String UPDATE_PIC_OK = "更新图片成功";
|
||||
public static String UPDATE_PIC_FAILED = "更新图片失败";
|
||||
|
||||
public static String INVALID_PARAM = "参数不合法";
|
||||
|
||||
public static String INVALID_USER = "登录失效,请重新登录";
|
||||
|
||||
public static String ADD_CART_OK = "加入购物车成功";
|
||||
public static String ADD_CART_FAILED = "加入购物车失败";
|
||||
|
||||
public static String BUY_OK = "下单成功";
|
||||
|
||||
public static String UPDATE_ORDER_OK = "订单发货状态更新成功";
|
||||
public static String ERROR_FILE_TYPE = "错误的文件类型";
|
||||
|
||||
public static String GOODS_UP_OK = "商品上架成功";
|
||||
public static String GOODS_DOWN_OK = "商品下架成功";
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package com.shanzhu.flower.config;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* 请求处理拦截器
|
||||
*
|
||||
* @author: ShanZhu
|
||||
* @date: 2024-01-24
|
||||
*/
|
||||
@Component
|
||||
public class ProcessInterceptor implements HandlerInterceptor {
|
||||
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o) throws Exception {
|
||||
httpServletResponse.setHeader("Access-Control-Allow-Origin", "*");
|
||||
httpServletResponse.setHeader("Access-Control-Allow-Headers", "Content-Type,Content-Length, Authorization, Accept,X-Requested-With");
|
||||
httpServletResponse.setHeader("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS");
|
||||
httpServletResponse.setHeader("X-Powered-By", "Jetty");
|
||||
String method = httpServletRequest.getMethod();
|
||||
if (method.equals("OPTIONS")) {
|
||||
httpServletResponse.setStatus(200);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterCompletion(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) throws Exception {
|
||||
}
|
||||
}
|
@ -0,0 +1,176 @@
|
||||
package com.shanzhu.flower.controller;
|
||||
|
||||
import com.shanzhu.flower.config.Constant;
|
||||
import com.shanzhu.flower.config.HttpMsg;
|
||||
import com.shanzhu.flower.dao.FlowersDao;
|
||||
import com.shanzhu.flower.entity.Cart;
|
||||
import com.shanzhu.flower.entity.R;
|
||||
import com.shanzhu.flower.service.CartService;
|
||||
import com.shanzhu.flower.service.OrderService;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import tk.mybatis.mapper.util.StringUtil;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* 购物车 控制层
|
||||
*
|
||||
* @author: ShanZhu
|
||||
* @date: 2024-01-24
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("cart")
|
||||
public class CartController {
|
||||
|
||||
@Resource
|
||||
private CartService cartService;
|
||||
|
||||
@Resource
|
||||
private OrderService orderService;
|
||||
|
||||
@Resource
|
||||
private FlowersDao flowersDao;
|
||||
|
||||
/**
|
||||
* 查询用户购物车
|
||||
*
|
||||
* @param account 用户账号
|
||||
* @return 购物车
|
||||
*/
|
||||
@RequestMapping("/queryByAccount")
|
||||
R queryByAccount(@RequestParam("account") String account) {
|
||||
R r = new R();
|
||||
|
||||
if (StringUtil.isEmpty(account)) {
|
||||
return r.setCode(4000).setMsg(HttpMsg.INVALID_PARAM);
|
||||
}
|
||||
|
||||
List<Cart> carts = cartService.queryByAccount(account);
|
||||
|
||||
for (Cart cart : carts) {
|
||||
float price = flowersDao.queryPrice(cart.getFid());
|
||||
cart.setPrice(cart.getAmount() * price);
|
||||
}
|
||||
|
||||
return r.setCode(2000).setData(carts);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 分页查询购物车
|
||||
*
|
||||
* @param page 页数
|
||||
* @param searchKey 查询条件
|
||||
* @param account 账户
|
||||
* @return 购物车列表
|
||||
*/
|
||||
@RequestMapping("/find")
|
||||
R find(
|
||||
@RequestParam("page") int page,
|
||||
@RequestParam("searchKey") String searchKey,
|
||||
@RequestParam("account") String account
|
||||
) {
|
||||
|
||||
R r = new R();
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
List<Cart> carts = cartService.find(searchKey, account);
|
||||
|
||||
if (carts == null) {
|
||||
return r.setCode(2000);
|
||||
}
|
||||
|
||||
List<Cart> items = carts.size() >= page * Constant.PAGE_SIZE ?
|
||||
carts.subList((page - 1) * Constant.PAGE_SIZE, page * Constant.PAGE_SIZE)
|
||||
: carts.subList((page - 1) * Constant.PAGE_SIZE, carts.size());
|
||||
|
||||
int len = carts.size() % Constant.PAGE_SIZE == 0 ? carts.size() / Constant.PAGE_SIZE
|
||||
: (carts.size() / Constant.PAGE_SIZE + 1);
|
||||
map.put("items", items);
|
||||
map.put("len", len);
|
||||
|
||||
return r.setCode(2000).setData(map);
|
||||
}
|
||||
|
||||
/**
|
||||
* 购买
|
||||
*
|
||||
* @param account 账号
|
||||
* @return 结果
|
||||
*/
|
||||
@RequestMapping("/buy")
|
||||
R buy(@RequestParam("account") String account) {
|
||||
R r = new R();
|
||||
|
||||
// 查该用户的购物车
|
||||
List<Cart> carts = (List<Cart>) queryByAccount(account).getData();
|
||||
for (Cart cart : carts) {
|
||||
// 增加订单数据
|
||||
orderService.add(cart);
|
||||
// 删除购物车数据
|
||||
cartService.delete(cart.getId());
|
||||
}
|
||||
|
||||
return r.setCode(2000).setMsg(HttpMsg.BUY_OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增购物车
|
||||
*
|
||||
* @param cart 购物车信息
|
||||
* @return 购物车
|
||||
*/
|
||||
@RequestMapping("/create")
|
||||
R create(@RequestBody Cart cart) {
|
||||
R r = new R();
|
||||
|
||||
int ans = cartService.add(cart);
|
||||
|
||||
if (ans == 1) {
|
||||
return r.setCode(2000).setMsg(HttpMsg.ADD_CART_OK);
|
||||
}
|
||||
|
||||
return r.setCode(4000).setMsg(HttpMsg.ADD_CART_FAILED);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新购物车
|
||||
*
|
||||
* @param cart 购物车信息
|
||||
* @return 结果
|
||||
*/
|
||||
@RequestMapping("/update")
|
||||
R update(@RequestBody Cart cart) {
|
||||
R r = new R();
|
||||
|
||||
int ans = cartService.update(cart);
|
||||
|
||||
if (ans >= 0) {
|
||||
return r.setCode(2000).setMsg(HttpMsg.UPDATE_USER_OK);
|
||||
}
|
||||
|
||||
return r.setCode(4000).setMsg(HttpMsg.UPDATE_USER_FAILED);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除购物车
|
||||
*
|
||||
* @param id 购物车id
|
||||
* @return 结果
|
||||
*/
|
||||
@DeleteMapping("/delete")
|
||||
R delete(@RequestParam("id") int id) {
|
||||
R r = new R();
|
||||
int ans = cartService.delete(id);
|
||||
if (ans == 1) {
|
||||
return r.setCode(2000).setMsg(HttpMsg.DELETE_USER_OK);
|
||||
}
|
||||
return r.setCode(4000).setMsg(HttpMsg.DELETE_USER_FAILED);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,244 @@
|
||||
package com.shanzhu.flower.controller;
|
||||
|
||||
import com.shanzhu.flower.config.Constant;
|
||||
import com.shanzhu.flower.config.HttpMsg;
|
||||
import com.shanzhu.flower.dao.FlowersDao;
|
||||
import com.shanzhu.flower.entity.Flower;
|
||||
import com.shanzhu.flower.entity.R;
|
||||
import com.shanzhu.flower.service.FlowersService;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
|
||||
/**
|
||||
* 鲜花 控制层
|
||||
*
|
||||
* @author: ShanZhu
|
||||
* @date: 2024-01-24
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("flower")
|
||||
public class FlowerController {
|
||||
|
||||
@Value("${uploadPath}")
|
||||
private String uploadPath;
|
||||
|
||||
@Resource
|
||||
private FlowersService flowerService;
|
||||
@Resource
|
||||
private FlowersDao flowersDao;
|
||||
|
||||
/**
|
||||
* 分页查询鲜花商品
|
||||
*
|
||||
* @param page 页数
|
||||
* @param searchKey 查询条件
|
||||
* @param searchType 查询类型
|
||||
* @return 商品
|
||||
*/
|
||||
@RequestMapping("/find")
|
||||
R find(
|
||||
@RequestParam("page") int page,
|
||||
@RequestParam("searchKey") String searchKey,
|
||||
@RequestParam("searchType") String searchType
|
||||
) {
|
||||
R r = new R();
|
||||
List<Flower> flowers = flowerService.find(searchKey, searchType);
|
||||
|
||||
if (flowers == null) {
|
||||
return r.setCode(2000);
|
||||
}
|
||||
|
||||
return getResponse(flowers, page, Constant.SHOW_PAGE_SIZE, r);
|
||||
}
|
||||
|
||||
/**
|
||||
* 管理员查询所有
|
||||
*
|
||||
* @param page 分页页数
|
||||
* @param searchKey 查询条件
|
||||
* @return 结果
|
||||
*/
|
||||
@RequestMapping("/findAll")
|
||||
R findAll(@RequestParam("page") int page, @RequestParam("searchKey") String searchKey) {
|
||||
R r = new R();
|
||||
List<Flower> flowers = flowerService.findAll(searchKey);
|
||||
|
||||
if (flowers == null) {
|
||||
return r.setCode(2000);
|
||||
}
|
||||
|
||||
return getResponse(flowers, page, Constant.PAGE_SIZE, r);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建鲜花商品
|
||||
*
|
||||
* @param flower 商品信息
|
||||
* @return 结果
|
||||
*/
|
||||
@RequestMapping("/create")
|
||||
R create(@RequestBody Flower flower) {
|
||||
R r = new R();
|
||||
|
||||
int ans = flowerService.add(flower);
|
||||
if (ans == 1) {
|
||||
return r.setCode(2000).setMsg(HttpMsg.ADD_FLOWER_OK);
|
||||
}
|
||||
|
||||
return r.setCode(4000).setMsg(HttpMsg.ADD_FLOWER_FAILED);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新鲜花商品
|
||||
*
|
||||
* @param flower 商品信息
|
||||
* @return 结果
|
||||
*/
|
||||
@RequestMapping("/update")
|
||||
R update(@RequestBody Flower flower) {
|
||||
R r = new R();
|
||||
|
||||
int ans = flowerService.update(flower);
|
||||
if (ans >= 0) {
|
||||
return r.setCode(2000).setMsg(HttpMsg.UPDATE_FLOWER_OK);
|
||||
}
|
||||
|
||||
return r.setCode(4000).setMsg(HttpMsg.UPDATE_FLOWER_FAILED);
|
||||
}
|
||||
|
||||
/**
|
||||
* 改版商品状态
|
||||
*
|
||||
* @param flower 商品信息
|
||||
* @return 结果
|
||||
*/
|
||||
@RequestMapping("/changeState")
|
||||
R changeState(@RequestBody Flower flower) {
|
||||
R r = new R();
|
||||
|
||||
flowersDao.changeState(flower);
|
||||
String msg = flower.getState() == 1 ? HttpMsg.GOODS_UP_OK : HttpMsg.GOODS_DOWN_OK;
|
||||
|
||||
return r.setCode(2000).setMsg(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传图片
|
||||
*
|
||||
* @param file 文件信息
|
||||
* @return 结果
|
||||
*/
|
||||
@RequestMapping("/updateImg")
|
||||
R updateImg(@RequestParam("file") MultipartFile file) {
|
||||
R r = new R();
|
||||
|
||||
// 只接收 jpg/png 图片
|
||||
String filename = file.getOriginalFilename();
|
||||
if (!filename.endsWith(".jpg") && !filename.endsWith(".png")) {
|
||||
return r.setCode(4000).setMsg(HttpMsg.ERROR_FILE_TYPE);
|
||||
}
|
||||
|
||||
String img_guid = UUID.randomUUID().toString().replaceAll("-", "") + ".jpg";
|
||||
|
||||
try {
|
||||
savePic(file.getInputStream(), img_guid);
|
||||
return r.setCode(2000).setMsg(HttpMsg.UPDATE_PIC_OK).setData(img_guid);
|
||||
} catch (IOException e) {
|
||||
return r.setCode(4000).setMsg(HttpMsg.UPDATE_PIC_FAILED);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新图片guid
|
||||
*
|
||||
* @param guid guid
|
||||
* @param id id
|
||||
* @return 结果
|
||||
*/
|
||||
@PutMapping("/updateImgGuid")
|
||||
R updateImgGuid(@RequestParam("guid") String guid, @RequestParam("id") int id) {
|
||||
R r = new R();
|
||||
|
||||
int ans = flowerService.updateImg(guid, id);
|
||||
if (ans == 1) {
|
||||
return r.setCode(2000).setMsg(HttpMsg.UPDATE_PIC_OK);
|
||||
}
|
||||
|
||||
return r.setCode(4000).setMsg(HttpMsg.UPDATE_PIC_FAILED);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除图片
|
||||
*
|
||||
* @param id 图片id
|
||||
* @return 结果
|
||||
*/
|
||||
@DeleteMapping("/delete")
|
||||
R delete(@RequestParam("id") int id) {
|
||||
R r = new R();
|
||||
|
||||
int ans = flowerService.delete(id);
|
||||
if (ans == 1) {
|
||||
return r.setCode(2000).setMsg(HttpMsg.DELETE_FLOWER_OK);
|
||||
}
|
||||
|
||||
return r.setCode(4000).setMsg(HttpMsg.DELETE_FLOWER_FAILED);
|
||||
}
|
||||
|
||||
private void savePic(InputStream inputStream, String fileName) {
|
||||
OutputStream os = null;
|
||||
try {
|
||||
String path = uploadPath;
|
||||
// 1K的数据缓冲
|
||||
byte[] bs = new byte[1024];
|
||||
// 读取到的数据长度
|
||||
int len;
|
||||
// 输出的文件流保存到本地文件
|
||||
os = new FileOutputStream(new File(path + fileName));
|
||||
// 开始读取
|
||||
while ((len = inputStream.read(bs)) != -1) {
|
||||
os.write(bs, 0, len);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
// 完毕,关闭所有链接
|
||||
try {
|
||||
os.close();
|
||||
inputStream.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private R getResponse(List<Flower> flowers, int page, int pageSize, R r) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
List<Flower> items = flowers.size() >= page * pageSize ?
|
||||
flowers.subList((page - 1) * pageSize, page * pageSize)
|
||||
: flowers.subList((page - 1) * pageSize, flowers.size());
|
||||
int len = flowers.size() % pageSize == 0 ? flowers.size() / pageSize
|
||||
: (flowers.size() / pageSize + 1);
|
||||
for (Flower item : items) {
|
||||
if (item.getImg_guid() == null) {
|
||||
item.setImg_guid(Constant.DEFAULT_IMG);
|
||||
}
|
||||
item.setImg_guid(Constant.IMG_USE_PATH + item.getImg_guid());
|
||||
}
|
||||
map.put("items", items);
|
||||
map.put("len", len);
|
||||
return r.setCode(2000).setData(map);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,88 @@
|
||||
package com.shanzhu.flower.controller;
|
||||
|
||||
import com.shanzhu.flower.config.Constant;
|
||||
import com.shanzhu.flower.config.HttpMsg;
|
||||
import com.shanzhu.flower.entity.R;
|
||||
import com.shanzhu.flower.entity.Species;
|
||||
import com.shanzhu.flower.service.SpeciesService;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* 鲜花种类 控制层
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("species")
|
||||
public class FlowerTypeController {
|
||||
|
||||
@Resource
|
||||
private SpeciesService speciesService;
|
||||
|
||||
@RequestMapping("/findAll")
|
||||
R findAll() {
|
||||
R r = new R();
|
||||
List<Species> all = speciesService.findAll();
|
||||
if (all.size()<=0){
|
||||
return r.setCode(4000).setMsg(HttpMsg.NO_TYPE_NOW);
|
||||
}
|
||||
return r.setCode(2000).setData(all);
|
||||
}
|
||||
|
||||
@RequestMapping("/find")
|
||||
R find(@RequestParam("page") int page, @RequestParam("searchKey") String searchKey) {
|
||||
R r = new R();
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
List<Species> list = speciesService.find(searchKey);
|
||||
if (list == null) {
|
||||
return r.setCode(2000);
|
||||
}
|
||||
List<Species> items = list.size() >= page * Constant.PAGE_SIZE ?
|
||||
list.subList((page - 1) * Constant.PAGE_SIZE, page * Constant.PAGE_SIZE)
|
||||
: list.subList((page - 1) * Constant.PAGE_SIZE, list.size());
|
||||
int len = list.size() % Constant.PAGE_SIZE == 0 ? list.size() / Constant.PAGE_SIZE
|
||||
: (list.size() / Constant.PAGE_SIZE + 1);
|
||||
map.put("items", items);
|
||||
map.put("len", len);
|
||||
return r.setCode(2000).setData(map);
|
||||
}
|
||||
|
||||
@RequestMapping("/create")
|
||||
R create(@RequestBody Species species) {
|
||||
R r = new R();
|
||||
try {
|
||||
speciesService.add(species);
|
||||
return r.setCode(2000).setMsg(HttpMsg.ADD_TYPE_OK);
|
||||
} catch (Exception e) {
|
||||
return r.setCode(4000).setMsg(HttpMsg.ADD_TYPE_FAILED);
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping("/update")
|
||||
R update(@RequestBody Species species) {
|
||||
R r = new R();
|
||||
try {
|
||||
speciesService.update(species);
|
||||
return r.setCode(2000).setMsg(HttpMsg.UPDATE_TYPE_OK);
|
||||
} catch (Exception e) {
|
||||
return r.setCode(4000).setMsg(HttpMsg.UPDATE_TYPE_FAILED);
|
||||
}
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
R delete(@RequestParam("id") int id) {
|
||||
R r = new R();
|
||||
try {
|
||||
speciesService.delete(id);
|
||||
return r.setCode(2000).setMsg(HttpMsg.DELETE_TYPE_OK);
|
||||
} catch (Exception e) {
|
||||
return r.setCode(4000).setMsg(HttpMsg.DELETE_TYPE_FAILED);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,42 @@
|
||||
package com.shanzhu.flower.controller;
|
||||
|
||||
import com.shanzhu.flower.config.HttpMsg;
|
||||
import com.shanzhu.flower.dao.LoginDao;
|
||||
import com.shanzhu.flower.entity.LoginForm;
|
||||
import com.shanzhu.flower.entity.R;
|
||||
import com.shanzhu.flower.entity.User;
|
||||
import com.shanzhu.flower.util.VerifyUtil;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
|
||||
/**
|
||||
* 用户登录 控制层
|
||||
*
|
||||
* @author: ShanZhu
|
||||
* @date: 2024-01-24
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("login")
|
||||
public class LoginController {
|
||||
|
||||
@Resource
|
||||
private LoginDao loginDao;
|
||||
|
||||
@RequestMapping("/doLogin")
|
||||
R doLogin(@RequestBody LoginForm form) {
|
||||
R r = new R();
|
||||
if (!VerifyUtil.verifyLoginForm(form)) {
|
||||
return r.setCode(4000).setMsg(HttpMsg.ERROR_INPUT);
|
||||
}
|
||||
User loginUser = loginDao.login(form);
|
||||
if (loginUser != null) {
|
||||
return r.setCode(2000).setMsg("欢迎您:" + loginUser.getName()).setData(loginUser);
|
||||
}
|
||||
return r.setCode(4000).setMsg(HttpMsg.ERROR_VERIFY);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,119 @@
|
||||
package com.shanzhu.flower.controller;
|
||||
|
||||
import com.shanzhu.flower.config.Constant;
|
||||
import com.shanzhu.flower.config.HttpMsg;
|
||||
import com.shanzhu.flower.dao.OrderDao;
|
||||
import com.shanzhu.flower.dao.UserDao;
|
||||
import com.shanzhu.flower.entity.Order;
|
||||
import com.shanzhu.flower.entity.OrderVo;
|
||||
import com.shanzhu.flower.entity.R;
|
||||
import com.shanzhu.flower.entity.User;
|
||||
import com.shanzhu.flower.service.OrderService;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import tk.mybatis.mapper.util.StringUtil;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* 订单 控制层
|
||||
*
|
||||
* @author: ShanZhu
|
||||
* @date: 2024-01-24
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("order")
|
||||
public class OrderController {
|
||||
|
||||
@Resource
|
||||
private OrderService orderService;
|
||||
|
||||
@Resource
|
||||
private UserDao userDao;
|
||||
|
||||
@Resource
|
||||
private OrderDao orderDao;
|
||||
|
||||
@RequestMapping("/queryByAccount")
|
||||
R queryByAccount(@RequestParam("account") String account) {
|
||||
R r = new R();
|
||||
if (StringUtil.isEmpty(account)) {
|
||||
return r.setCode(4000).setMsg(HttpMsg.INVALID_PARAM);
|
||||
}
|
||||
List<Order> orders = orderService.queryByAccount(account);
|
||||
return r.setCode(2000).setData(orders);
|
||||
}
|
||||
|
||||
@RequestMapping("/find")
|
||||
R find(@RequestParam("page") int page, @RequestParam("searchKey") String searchKey, @RequestParam("account") String account) {
|
||||
R r = new R();
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
List<Order> orders = orderService.find(searchKey, account);
|
||||
if (orders == null) {
|
||||
return r.setCode(2000);
|
||||
}
|
||||
map.put("items", orders);
|
||||
map.put("len", orders.size());
|
||||
return r.setCode(2000).setData(map);
|
||||
}
|
||||
|
||||
@RequestMapping("/findAll")
|
||||
R findAll(@RequestParam("page") int page, @RequestParam("searchKey") String searchKey) {
|
||||
R r = new R();
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
List<Order> orders = orderService.findAll(searchKey);
|
||||
if (orders == null) {
|
||||
return r.setCode(2000);
|
||||
}
|
||||
List<Order> items = orders.size() >= page * Constant.PAGE_SIZE ?
|
||||
orders.subList((page - 1) * Constant.PAGE_SIZE, page * Constant.PAGE_SIZE)
|
||||
: orders.subList((page - 1) * Constant.PAGE_SIZE, orders.size());
|
||||
int len = orders.size() % Constant.PAGE_SIZE == 0 ? orders.size() / Constant.PAGE_SIZE
|
||||
: (orders.size() / Constant.PAGE_SIZE + 1);
|
||||
List<OrderVo> vos = new ArrayList<>();
|
||||
for (Order item : items) {
|
||||
User user = userDao.queryById(item.getUid());
|
||||
OrderVo vo = new OrderVo();
|
||||
vo.setAddress(user.getAddress()).setPhone(user.getPhone()).setUsername(user.getName())
|
||||
.setAmount(item.getAmount()).setFlower(item.getFlower()).setId(item.getId())
|
||||
.setUid(item.getUid()).setOrder_guid(item.getOrder_guid()).setPrice(item.getPrice())
|
||||
.setState(item.getState());
|
||||
vos.add(vo);
|
||||
}
|
||||
map.put("items", vos);
|
||||
map.put("len", len);
|
||||
return r.setCode(2000).setData(map);
|
||||
}
|
||||
|
||||
@RequestMapping("/update")
|
||||
R update(@RequestBody Order order) {
|
||||
R r = new R();
|
||||
int ans = orderService.update(order);
|
||||
if (ans >= 0) {
|
||||
return r.setCode(2000).setMsg(HttpMsg.UPDATE_USER_OK);
|
||||
}
|
||||
return r.setCode(4000).setMsg(HttpMsg.UPDATE_USER_FAILED);
|
||||
}
|
||||
|
||||
@RequestMapping("/changeState")
|
||||
R changeState(@RequestBody Order order) {
|
||||
orderDao.changeState(order);
|
||||
return new R().setCode(2000).setMsg(HttpMsg.UPDATE_ORDER_OK);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
R delete(@RequestParam("id") int id) {
|
||||
R r = new R();
|
||||
int ans = orderService.delete(id);
|
||||
if (ans == 1) {
|
||||
return r.setCode(2000).setMsg(HttpMsg.DELETE_USER_OK);
|
||||
}
|
||||
return r.setCode(4000).setMsg(HttpMsg.DELETE_USER_FAILED);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,92 @@
|
||||
package com.shanzhu.flower.controller;
|
||||
|
||||
import com.shanzhu.flower.config.Constant;
|
||||
import com.shanzhu.flower.config.HttpMsg;
|
||||
import com.shanzhu.flower.entity.R;
|
||||
import com.shanzhu.flower.entity.User;
|
||||
import com.shanzhu.flower.service.UserService;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import tk.mybatis.mapper.util.StringUtil;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* 用户 控制层
|
||||
*
|
||||
* @author: ShanZhu
|
||||
* @date: 2024-01-24
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("user")
|
||||
public class UserController {
|
||||
|
||||
@Resource
|
||||
private UserService userService;
|
||||
|
||||
@RequestMapping("/queryInfoByAccount")
|
||||
R queryInfoByAccount(@RequestParam("account") String account) {
|
||||
R r = new R();
|
||||
if (StringUtil.isEmpty(account)){
|
||||
return r.setCode(4000).setMsg(HttpMsg.INVALID_PARAM);
|
||||
}
|
||||
User loginUser = userService.queryInfo(account);
|
||||
if (loginUser == null){
|
||||
return r.setCode(4000).setMsg(HttpMsg.INVALID_USER);
|
||||
}
|
||||
return r.setCode(2000).setData(loginUser);
|
||||
}
|
||||
|
||||
@RequestMapping("/find")
|
||||
R find(@RequestParam("page") int page, @RequestParam("searchKey") String searchKey) {
|
||||
R r = new R();
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
List<User> users = userService.find(searchKey);
|
||||
if (users == null) {
|
||||
return r.setCode(2000);
|
||||
}
|
||||
List<User> items = users.size() >= page * Constant.PAGE_SIZE ?
|
||||
users.subList((page - 1) * Constant.PAGE_SIZE, page * Constant.PAGE_SIZE)
|
||||
: users.subList((page - 1) * Constant.PAGE_SIZE, users.size());
|
||||
int len = users.size() % Constant.PAGE_SIZE == 0 ? users.size() / Constant.PAGE_SIZE
|
||||
: (users.size() / Constant.PAGE_SIZE + 1);
|
||||
map.put("items", items);
|
||||
map.put("len", len);
|
||||
return r.setCode(2000).setData(map);
|
||||
}
|
||||
|
||||
@RequestMapping("/create")
|
||||
R create(@RequestBody User user) {
|
||||
R r = new R();
|
||||
int ans = userService.add(user);
|
||||
if (ans == 1) {
|
||||
return r.setCode(2000).setMsg(HttpMsg.ADD_USER_OK);
|
||||
}
|
||||
return r.setCode(4000).setMsg(HttpMsg.ADD_USER_FAILED);
|
||||
}
|
||||
|
||||
@RequestMapping("/update")
|
||||
R update(@RequestBody User user) {
|
||||
R r = new R();
|
||||
int ans = userService.update(user);
|
||||
if (ans >= 0) {
|
||||
return r.setCode(2000).setMsg(HttpMsg.UPDATE_USER_OK);
|
||||
}
|
||||
return r.setCode(4000).setMsg(HttpMsg.UPDATE_USER_FAILED);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
R delete(@RequestParam("id") int id) {
|
||||
R r = new R();
|
||||
int ans = userService.delete(id);
|
||||
if (ans == 1) {
|
||||
return r.setCode(2000).setMsg(HttpMsg.DELETE_USER_OK);
|
||||
}
|
||||
return r.setCode(4000).setMsg(HttpMsg.DELETE_USER_FAILED);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,41 @@
|
||||
package com.shanzhu.flower.dao;
|
||||
|
||||
import com.shanzhu.flower.entity.Cart;
|
||||
import org.apache.ibatis.annotations.*;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public interface CartDao {
|
||||
|
||||
@Select("select * from carts where flower like concat('%',#{searchKey},'%') and account = #{account};")
|
||||
List<Cart> find(@Param("searchKey") String searchKey, @Param("account") String account);
|
||||
|
||||
@Select("select * from carts;")
|
||||
List<Cart> findAll();
|
||||
|
||||
@Select("select * from carts where fid = #{fid} and uid = #{uid};")
|
||||
Cart checkIsAdded(Cart cart);
|
||||
|
||||
@Update("update carts set amount = amount + 1 where fid = #{fid} and uid = #{uid};")
|
||||
int addAmount(Cart cart);
|
||||
|
||||
@Select("select * from carts where uid = #{uid};")
|
||||
List<Cart> queryByUid(int uid);
|
||||
|
||||
@Update("update carts set name = #{name},password = #{password},phone = #{phone},address = #{address} where id = #{id};")
|
||||
int update(Cart cart);
|
||||
|
||||
@Delete("delete from carts where id = #{id};")
|
||||
int delete(int id);
|
||||
|
||||
@Insert("insert into carts(fid,flower,amount,uid) " +
|
||||
"values(#{fid},#{flower},1,#{uid});")
|
||||
int add(Cart cart);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,41 @@
|
||||
package com.shanzhu.flower.dao;
|
||||
|
||||
import com.shanzhu.flower.entity.Flower;
|
||||
import org.apache.ibatis.annotations.*;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public interface FlowersDao {
|
||||
|
||||
@Select("select * from flowers where name like concat('%',#{searchKey},'%') " +
|
||||
"and species_name like concat('%',#{searchType},'%') and state = 1;")
|
||||
List<Flower> find(@Param("searchKey") String searchKey, @Param("searchType")String searchType);
|
||||
|
||||
@Select("select * from flowers where name like concat('%',#{searchKey},'%');")
|
||||
List<Flower> findAll(String searchKey);
|
||||
|
||||
@Select("select price from flowers where id = #{fid};")
|
||||
Float queryPrice(int fid);
|
||||
|
||||
@Update("update flowers set name = #{name}, species_name = #{species_name}, price = #{price}, detail = #{detail} where id = #{id};")
|
||||
Integer update(Flower flower);
|
||||
|
||||
@Update("update flowers set img_guid = #{img_guid} where id = #{id};")
|
||||
Integer updateImg(@Param("img_guid") String img_guid,@Param("id") Integer id);
|
||||
|
||||
@Update("update flowers set state = ${state} where id = #{id};")
|
||||
Integer changeState(Flower flower);
|
||||
|
||||
@Delete("delete from flowers where id = #{id};")
|
||||
Integer delete(int id);
|
||||
|
||||
@Insert("insert into flowers(name,species_name,price,detail,state) values(#{name},#{species_name},${price},#{detail},1);")
|
||||
Integer add(Flower flower);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,18 @@
|
||||
package com.shanzhu.flower.dao;
|
||||
|
||||
import com.shanzhu.flower.entity.LoginForm;
|
||||
import com.shanzhu.flower.entity.User;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface LoginDao {
|
||||
|
||||
@Select("select * from users where account = #{account} and password = #{password} and role = #{role};")
|
||||
User login(LoginForm form);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,44 @@
|
||||
package com.shanzhu.flower.dao;
|
||||
|
||||
import com.shanzhu.flower.entity.Cart;
|
||||
import com.shanzhu.flower.entity.Order;
|
||||
import org.apache.ibatis.annotations.*;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public interface OrderDao {
|
||||
|
||||
@Select("select * from orders where flower like concat('%',#{searchKey},'%') and uid = #{uid};")
|
||||
List<Order> find(@Param("searchKey") String searchKey, @Param("uid") int uid);
|
||||
|
||||
@Select("select * from orders where flower like concat('%',#{searchKey},'%');")
|
||||
List<Order> findAll(String searchKey);
|
||||
|
||||
|
||||
@Select("select * from orders where fid = #{fid} and uid = #{uid};")
|
||||
Order checkIsAdded(Order order);
|
||||
|
||||
|
||||
@Update("update orders set state = #{state} where id = #{id};")
|
||||
int changeState(Order order);
|
||||
|
||||
@Select("select * from orders where uid = #{uid};")
|
||||
List<Order> queryByUid(int uid);
|
||||
|
||||
@Update("update orders set name = #{name},password = #{password},phone = #{phone},address = #{address} where id = #{id};")
|
||||
int update(Order order);
|
||||
|
||||
@Delete("delete from orders where id = #{id};")
|
||||
int delete(int id);
|
||||
|
||||
@Insert("insert into orders(flower,amount,price,state,uid) " +
|
||||
"values(#{flower},#{amount},#{price},0,#{uid});")
|
||||
int add(Cart cart);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,34 @@
|
||||
package com.shanzhu.flower.dao;
|
||||
|
||||
import com.shanzhu.flower.entity.Species;
|
||||
import org.apache.ibatis.annotations.Delete;
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public interface SpeciesDao {
|
||||
|
||||
@Select("select * from species where species_name like concat('%',#{searchKey},'%');")
|
||||
List<Species> find(String searchKey);
|
||||
|
||||
@Select("select * from species;")
|
||||
List<Species> findAll();
|
||||
|
||||
@Update("update species set species_name = #{species_name} where id = #{id};")
|
||||
int update(Species species);
|
||||
|
||||
@Delete("delete from species where id = #{id};")
|
||||
int delete(int id);
|
||||
|
||||
@Insert("insert into species(species_name) values(#{species_name});")
|
||||
int add(Species species);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,44 @@
|
||||
package com.shanzhu.flower.dao;
|
||||
|
||||
import com.shanzhu.flower.entity.User;
|
||||
import org.apache.ibatis.annotations.Delete;
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public interface UserDao {
|
||||
|
||||
@Select("select * from users where (account like concat('%',#{searchKey},'%') or name like concat('%',#{searchKey},'%')) and role = 'user';")
|
||||
List<User> find(String searchKey);
|
||||
|
||||
@Select("select * from users where id = #{id};")
|
||||
User queryById(Integer id);
|
||||
|
||||
@Select("select * from users;")
|
||||
List<User> findAll();
|
||||
|
||||
@Select("select * from users where account = #{account} and role = 'user';")
|
||||
User queryInfo(String account);
|
||||
|
||||
@Select("select id from users where account = #{account} and role = 'user';")
|
||||
Integer queryIdByAccount(String account);
|
||||
|
||||
@Update("update users set name = #{name},password = #{password},phone = #{phone},address = #{address} where id = #{id};")
|
||||
int update(User user);
|
||||
|
||||
@Delete("delete from users where id = #{id};")
|
||||
int delete(int id);
|
||||
|
||||
@Insert("insert into users(account,name,password,phone,address,role) " +
|
||||
"values(#{account},#{name},#{password},#{phone},#{address},'user');")
|
||||
int add(User user);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,19 @@
|
||||
package com.shanzhu.flower.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class Cart {
|
||||
|
||||
private int id;
|
||||
private int fid;
|
||||
private String flower;
|
||||
private int amount;
|
||||
private float price;
|
||||
private int uid;
|
||||
private String account;
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,25 @@
|
||||
package com.shanzhu.flower.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class Flower {
|
||||
|
||||
private int id;
|
||||
private String name;
|
||||
// 分类名称
|
||||
private String species_name;
|
||||
private float price;
|
||||
// 详细介绍
|
||||
private String detail;
|
||||
// 图片
|
||||
private String img_guid;
|
||||
// 是否上架
|
||||
private int state;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -0,0 +1,12 @@
|
||||
package com.shanzhu.flower.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class LoginForm {
|
||||
private String account;
|
||||
private String password;
|
||||
private String role;
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package com.shanzhu.flower.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class Order {
|
||||
|
||||
private int id;
|
||||
private String order_guid;
|
||||
private String flower;
|
||||
private int amount;
|
||||
private float price;
|
||||
private float state;
|
||||
// 用户 id
|
||||
private int uid;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -0,0 +1,17 @@
|
||||
package com.shanzhu.flower.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class OrderVo extends Order{
|
||||
|
||||
private String username;
|
||||
private String phone;
|
||||
private String address;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -0,0 +1,11 @@
|
||||
package com.shanzhu.flower.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class Param {
|
||||
private String searchKey;
|
||||
private int page;
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package com.shanzhu.flower.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class R {
|
||||
private int code;
|
||||
private String msg;
|
||||
private Object data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -0,0 +1,15 @@
|
||||
package com.shanzhu.flower.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class Species {
|
||||
private int id;
|
||||
private String species_name;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -0,0 +1,19 @@
|
||||
package com.shanzhu.flower.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class User {
|
||||
private int id;
|
||||
private String account;
|
||||
private String name;
|
||||
private String password;
|
||||
private String phone;
|
||||
private String address;
|
||||
private String role;
|
||||
}
|
||||
|
||||
|
||||
|
@ -0,0 +1,20 @@
|
||||
package com.shanzhu.flower.service;
|
||||
|
||||
import com.shanzhu.flower.entity.Cart;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 购物车 服务
|
||||
*
|
||||
* @author: ShanZhu
|
||||
* @date: 2024-01-24
|
||||
*/
|
||||
public interface CartService {
|
||||
|
||||
int add(Cart cart);
|
||||
int delete(int uid);
|
||||
int update(Cart cart);
|
||||
List<Cart> find(String searchKey,String account);
|
||||
List<Cart> queryByAccount(String account);
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package com.shanzhu.flower.service;
|
||||
|
||||
import com.shanzhu.flower.entity.Flower;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 鲜花商品 服务层
|
||||
*
|
||||
* @author: ShanZhu
|
||||
* @date: 2024-01-24
|
||||
*/
|
||||
public interface FlowersService {
|
||||
|
||||
int add(Flower flower);
|
||||
int delete(int id);
|
||||
int update(Flower flower);
|
||||
List<Flower> find(String searchKey,String searchType);
|
||||
List<Flower> findAll(String searchKey);
|
||||
int updateImg(String img_guid,Integer id);
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package com.shanzhu.flower.service;
|
||||
|
||||
import com.shanzhu.flower.entity.Cart;
|
||||
import com.shanzhu.flower.entity.Order;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 订单 服务层
|
||||
*
|
||||
* @author: ShanZhu
|
||||
* @date: 2024-01-24
|
||||
*/
|
||||
public interface OrderService {
|
||||
|
||||
int add(Cart cart);
|
||||
int delete(int uid);
|
||||
int update(Order order);
|
||||
List<Order> find(String searchKey, String account);
|
||||
List<Order> findAll(String searchKey);
|
||||
List<Order> queryByAccount(String account);
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package com.shanzhu.flower.service;
|
||||
|
||||
import com.shanzhu.flower.entity.Species;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface SpeciesService {
|
||||
|
||||
int add(Species species);
|
||||
int delete(int id);
|
||||
int update(Species species);
|
||||
List<Species> find(String searchKey);
|
||||
List<Species> findAll();
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package com.shanzhu.flower.service;
|
||||
|
||||
import com.shanzhu.flower.entity.User;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用户 服务层
|
||||
*
|
||||
* @author: ShanZhu
|
||||
* @date: 2024-01-24
|
||||
*/
|
||||
public interface UserService {
|
||||
|
||||
int add(User user);
|
||||
int delete(int uid);
|
||||
int update(User user);
|
||||
List<User> find(String searchKey);
|
||||
User queryInfo(String account);
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package com.shanzhu.flower.service.impl;
|
||||
|
||||
import com.shanzhu.flower.dao.CartDao;
|
||||
import com.shanzhu.flower.dao.UserDao;
|
||||
import com.shanzhu.flower.entity.Cart;
|
||||
import com.shanzhu.flower.service.CartService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class CartServiceImpl implements CartService {
|
||||
|
||||
@Resource
|
||||
private CartDao cartDao;
|
||||
|
||||
@Resource
|
||||
private UserDao userDao;
|
||||
|
||||
@Override
|
||||
public int add(Cart cart) {
|
||||
int uid = userDao.queryIdByAccount(cart.getAccount());
|
||||
cart.setUid(uid);
|
||||
Cart cart1 = cartDao.checkIsAdded(cart);
|
||||
if (cart1==null){
|
||||
return cartDao.add(cart);
|
||||
}else {
|
||||
return cartDao.addAmount(cart);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int delete(int uid) {
|
||||
return cartDao.delete(uid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int update(Cart cart) {
|
||||
return cartDao.update(cart);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Cart> find(String searchKey,String account) {
|
||||
return cartDao.find(searchKey,account);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Cart> queryByAccount(String account) {
|
||||
Integer uid = userDao.queryIdByAccount(account);
|
||||
return cartDao.queryByUid(uid);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
package com.shanzhu.flower.service.impl;
|
||||
|
||||
import com.shanzhu.flower.dao.FlowersDao;
|
||||
import com.shanzhu.flower.entity.Flower;
|
||||
import com.shanzhu.flower.service.FlowersService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class FlowersServiceImpl implements FlowersService {
|
||||
|
||||
@Resource
|
||||
private FlowersDao flowersDao;
|
||||
|
||||
@Override
|
||||
public int add(Flower flower) {
|
||||
return flowersDao.add(flower);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int delete(int id) {
|
||||
return flowersDao.delete(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int update(Flower flower) {
|
||||
return flowersDao.update(flower);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Flower> find(String searchKey,String searchType) {
|
||||
return flowersDao.find(searchKey,searchType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Flower> findAll(String searchKey) {
|
||||
return flowersDao.findAll(searchKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateImg(String img_guid,Integer id) {
|
||||
return flowersDao.updateImg(img_guid,id);
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package com.shanzhu.flower.service.impl;
|
||||
|
||||
import com.shanzhu.flower.dao.OrderDao;
|
||||
import com.shanzhu.flower.dao.UserDao;
|
||||
import com.shanzhu.flower.entity.Cart;
|
||||
import com.shanzhu.flower.entity.Order;
|
||||
import com.shanzhu.flower.service.OrderService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class OrderServiceImpl implements OrderService {
|
||||
|
||||
@Resource
|
||||
private OrderDao orderdao;
|
||||
|
||||
@Resource
|
||||
private UserDao userDao;
|
||||
|
||||
@Override
|
||||
public int add(Cart cart) {
|
||||
return orderdao.add(cart);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int delete(int uid) {
|
||||
return orderdao.delete(uid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int update(Order order) {
|
||||
return orderdao.update(order);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Order> find(String searchKey,String account) {
|
||||
Integer uid = userDao.queryIdByAccount(account);
|
||||
return orderdao.find(searchKey,uid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Order> findAll(String searchKey) {
|
||||
return orderdao.findAll(searchKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Order> queryByAccount(String account) {
|
||||
Integer uid = userDao.queryIdByAccount(account);
|
||||
return orderdao.queryByUid(uid);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package com.shanzhu.flower.service.impl;
|
||||
|
||||
import com.shanzhu.flower.dao.SpeciesDao;
|
||||
import com.shanzhu.flower.entity.Species;
|
||||
import com.shanzhu.flower.service.SpeciesService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class SpeciesServiceImpl implements SpeciesService {
|
||||
|
||||
@Resource
|
||||
private SpeciesDao speciesDao;
|
||||
|
||||
@Override
|
||||
public int add(Species species) {
|
||||
return speciesDao.add(species);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int delete(int uid) {
|
||||
return speciesDao.delete(uid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int update(Species species) {
|
||||
return speciesDao.update(species);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Species> find(String searchKey) {
|
||||
return speciesDao.find(searchKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Species> findAll() {
|
||||
return speciesDao.findAll();
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package com.shanzhu.flower.service.impl;
|
||||
|
||||
import com.shanzhu.flower.dao.UserDao;
|
||||
import com.shanzhu.flower.entity.User;
|
||||
import com.shanzhu.flower.service.UserService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class UserServiceImpl implements UserService {
|
||||
|
||||
@Resource
|
||||
private UserDao userdao;
|
||||
|
||||
@Override
|
||||
public int add(User user) {
|
||||
try {
|
||||
return userdao.add(user);
|
||||
}catch (Exception e){
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int delete(int uid) {
|
||||
return userdao.delete(uid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int update(User user) {
|
||||
return userdao.update(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<User> find(String searchKey) {
|
||||
return userdao.find(searchKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public User queryInfo(String account) {
|
||||
return userdao.queryInfo(account);
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package com.shanzhu.flower.util;
|
||||
|
||||
|
||||
import com.shanzhu.flower.entity.LoginForm;
|
||||
import tk.mybatis.mapper.util.StringUtil;
|
||||
|
||||
public class VerifyUtil {
|
||||
|
||||
public static boolean verifyLoginForm(LoginForm form) {
|
||||
if (form==null || StringUtil.isEmpty(form.getAccount())|| StringUtil.isEmpty(form.getPassword())|| StringUtil.isEmpty(form.getRole())) {
|
||||
return false;
|
||||
}
|
||||
if (form.getRole().equals("user") || form.getRole().equals("admin")){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
#后端服务端口
|
||||
server:
|
||||
port: 8081
|
||||
|
||||
spring:
|
||||
#数据库配置
|
||||
datasource:
|
||||
url: jdbc:mysql://localhost:3306/DB_flower?characterEncoding=UTF-8&serverTimezone=UTC
|
||||
username: root
|
||||
password: 123456
|
||||
|
||||
resources:
|
||||
chain:
|
||||
strategy:
|
||||
content:
|
||||
enabled: true
|
||||
paths: /**
|
||||
mybatis:
|
||||
type-aliases-package: com.shanzhu.flower.entity
|
||||
|
||||
#图片上传路径 图片所在的路径位置
|
||||
uploadPath: /Users/jiawang/saleProject/花店商城/flower-frontend/static/imgs/
|
Loading…
Reference in new issue