linruijin 2 months ago
parent 08b6e5ad69
commit 01986ab4f1

@ -0,0 +1,5 @@
# 默认忽略的文件
/shelf/
/workspace.xml
# 依赖于环境的 Maven 主目录路径
/mavenHomeManager.xml

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<annotationProcessing>
<profile name="Maven default annotation processors profile" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="springboot" />
</profile>
</annotationProcessing>
<bytecodeTargetLevel target="24">
<module name="farm_system" target="24" />
</bytecodeTargetLevel>
</component>
<component name="JavacSettings">
<option name="ADDITIONAL_OPTIONS_OVERRIDE">
<module name="springboot" options="-parameters" />
</option>
</component>
</project>

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="dataSourceStorageLocal" created-in="IU-252.25557.131">
<data-source name="jdbc:mysql://localhost:3306/farm_system?useUnicode=true&amp;characterEncoding=utf-8&amp;allowMultiQueries=true&amp;useSSL=false&amp;serverTimezone=GMT%2b8&amp;allowPublicKeyRetrieval=true [DEBUG]" uuid="fa60ffaf-6f39-4cbd-99f4-47e70b05a691">
<database-info product="" version="" jdbc-version="" driver-name="" driver-version="" dbms="MYSQL" />
<user-name>root</user-name>
<schema-mapping />
</data-source>
</component>
</project>

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
<data-source source="LOCAL" name="jdbc:mysql://localhost:3306/farm_system?useUnicode=true&amp;characterEncoding=utf-8&amp;allowMultiQueries=true&amp;useSSL=false&amp;serverTimezone=GMT%2b8&amp;allowPublicKeyRetrieval=true [DEBUG]" group="SpringbootApplication" uuid="fa60ffaf-6f39-4cbd-99f4-47e70b05a691">
<driver-ref>mysql.8</driver-ref>
<synchronize>true</synchronize>
<imported>true</imported>
<jdbc-driver>com.mysql.cj.jdbc.Driver</jdbc-driver>
<jdbc-url>jdbc:mysql://localhost:3306/farm_system?useUnicode=true&amp;characterEncoding=utf-8&amp;allowMultiQueries=true&amp;useSSL=false&amp;serverTimezone=GMT%2b8&amp;allowPublicKeyRetrieval=true</jdbc-url>
<working-dir>$ProjectFileDir$</working-dir>
</data-source>
</component>
</project>

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="file://$PROJECT_DIR$/springboot/src/main/java" charset="UTF-8" />
</component>
</project>

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RemoteRepositoriesConfiguration">
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Central Repository" />
<option name="url" value="https://repo.maven.apache.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Central repository" />
<option name="url" value="https://repo1.maven.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Central Repository" />
<option name="url" value="http://maven.aliyun.com/nexus/content/groups/public" />
</remote-repository>
<remote-repository>
<option name="id" value="jboss.community" />
<option name="name" value="JBoss Community repository" />
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
</remote-repository>
</component>
</project>

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/springboot/pom.xml" />
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_24" default="true" project-jdk-name="24" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/farm_system.iml" filepath="$PROJECT_DIR$/.idea/farm_system.iml" />
</modules>
</component>
</project>

Binary file not shown.

After

Width:  |  Height:  |  Size: 126 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 200 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 78 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 142 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 83 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 249 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 113 KiB

@ -0,0 +1,106 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Maven项目对象模型POM文件。
定义了项目的元数据、依赖项以及构建配置等信息。
-->
<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">
<!-- 指定当前POM模型的版本 -->
<modelVersion>4.0.0</modelVersion>
<!-- 继承Spring Boot父级POM用于管理默认配置和插件 -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.1</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<!-- 当前项目的GroupId通常表示组织或公司标识 -->
<groupId>com.ttl</groupId>
<!-- 当前项目的ArtifactId即项目模块名称 -->
<artifactId>springboot</artifactId>
<!-- 当前项目的版本号 -->
<version>0.0.1-SNAPSHOT</version>
<!-- 项目的显示名称 -->
<name>springboot</name>
<!-- 项目的简要描述 -->
<description>springboot</description>
<!-- 配置项目中使用的属性 -->
<properties>
<!-- 设置Java编译版本为21 -->
<java.version>21</java.version>
</properties>
<!-- 声明项目所需的依赖库 -->
<dependencies>
<!-- Spring Boot Web Starter提供Web开发所需的基础功能 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- MyBatis Spring Boot Starter集成MyBatis ORM框架 -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>3.0.3</version>
</dependency>
<!-- MySQL驱动程序在运行时使用 -->
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
</dependency>
<!-- Hutool工具类库提供了丰富的Java工具方法 -->
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.8.25</version>
</dependency>
<!-- PageHelper分页插件支持MyBatis的物理分页 -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.4.6</version>
<!-- 排除与mybatis starter冲突的mybatis依赖 -->
<exclusions>
<exclusion>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<!-- 构建相关的配置 -->
<build>
<!-- 插件列表 -->
<plugins>
<!-- Spring Boot Maven Plugin打包可执行jar/war文件 -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<!-- 排除Lombok依赖以避免在最终包中包含它 -->
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>

@ -0,0 +1,17 @@
package com.example;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
@MapperScan("com.example.mapper")
public class SpringbootApplication {
public static void main(String[] args) {
SpringApplication.run(SpringbootApplication.class, args);
}
}

@ -0,0 +1,43 @@
package com.example.common;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
/**
*
*/
@Configuration
public class CorsConfig {
/**
*
*
* @return CorsFilter
*/
@Bean
public CorsFilter corsFilter() {
// 创建基于URL的CORS配置源
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
// 创建CORS配置对象
CorsConfiguration corsConfiguration = new CorsConfiguration();
// 1. 设置允许访问的源地址为任意地址
corsConfiguration.addAllowedOrigin("*");
// 2. 设置允许的请求头为任意头信息
corsConfiguration.addAllowedHeader("*");
// 3. 设置允许的请求方法为任意方法(POST,GET等)
corsConfiguration.addAllowedMethod("*");
// 4. 对所有接口路径应用上述CORS配置
source.registerCorsConfiguration("/**", corsConfiguration);
// 返回配置好的跨域过滤器
return new CorsFilter(source);
}
}

@ -0,0 +1,121 @@
package com.example.common;
/**
*
*
*/
public class Result {
// 状态码
private String code;
// 返回消息
private String msg;
// 返回数据
private Object data;
/**
*
* @param data
*/
private Result(Object data) {
this.data = data;
}
/**
*
*/
public Result() {
}
/**
*
* @return Result code"200"msg"请求成功"
*/
public static Result success() {
Result result = new Result();
result.setCode("200");
result.setMsg("请求成功");
return result;
}
/**
*
* @param data
* @return Result
*/
public static Result success(Object data) {
Result result = success();
result.setData(data);
return result;
}
/**
*
* @return Result code"500"msg"请求失败"
*/
public static Result error() {
Result result = new Result();
result.setCode("500");
result.setMsg("请求失败");
return result;
}
/**
*
* @param msg
* @return Result
*/
public static Result error(String msg) {
Result result = new Result();
result.setCode("500");
result.setMsg(msg);
return result;
}
/**
*
* @return String
*/
public String getCode() {
return code;
}
/**
*
* @param code
*/
public void setCode(String code) {
this.code = code;
}
/**
*
* @return String
*/
public String getMsg() {
return msg;
}
/**
*
* @param msg
*/
public void setMsg(String msg) {
this.msg = msg;
}
/**
*
* @return Object
*/
public Object getData() {
return data;
}
/**
*
* @param data
*/
public void setData(Object data) {
this.data = data;
}
}

@ -0,0 +1,92 @@
package com.example.controller;
import com.example.common.Result;
import com.example.entity.Admin;
import com.example.service.AdminService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
*
**/
@RestController
@RequestMapping("/admin")
public class AdminController {
@Resource
private AdminService adminService;
/**
*
* @param admin
* @return Result.success()
*/
@PostMapping("/add")
public Result add(@RequestBody Admin admin) {
adminService.add(admin);
return Result.success();
}
/**
* ID
* @param id ID
* @return Result.success()
*/
@DeleteMapping("/delete/{id}")
public Result deleteById(@PathVariable Integer id) {
adminService.deleteById(id);
return Result.success();
}
/**
*
* @param admin
* @return Result.success()
*/
@PutMapping("/update")
public Result updateById(@RequestBody Admin admin) {
adminService.updateById(admin);
return Result.success();
}
/**
* ID
* @param id ID
* @return Result
*/
@GetMapping("/selectById/{id}")
public Result selectById(@PathVariable Integer id) {
Admin admin = adminService.selectById(id);
return Result.success(admin);
}
/**
*
* @param admin
* @return Result
*/
@GetMapping("/selectAll")
public Result selectAll(Admin admin) {
List<Admin> list = adminService.selectAll(admin);
return Result.success(list);
}
/**
*
* @param admin
* @param pageNum 1
* @param pageSize 10
* @return Result
*/
@GetMapping("/selectPage")
public Result selectPage(Admin admin,
@RequestParam(defaultValue = "1") Integer pageNum,
@RequestParam(defaultValue = "10") Integer pageSize) {
PageInfo<Admin> page = adminService.selectPage(admin, pageNum, pageSize);
return Result.success(page);
}
}

@ -0,0 +1,78 @@
package com.example.controller;
import com.example.common.Result;
import com.example.entity.Category;
import com.example.service.CategoryService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
*
**/
@RestController
@RequestMapping("/category")
public class CategoryController {
@Resource
private CategoryService categoryService;
/**
*
*/
@PostMapping("/add")
public Result add(@RequestBody Category category) {
categoryService.add(category);
return Result.success();
}
/**
*
*/
@DeleteMapping("/delete/{id}")
public Result deleteById(@PathVariable Integer id) {
categoryService.deleteById(id);
return Result.success();
}
/**
*
*/
@PutMapping("/update")
public Result updateById(@RequestBody Category category) {
categoryService.updateById(category);
return Result.success();
}
/**
* ID
*/
@GetMapping("/selectById/{id}")
public Result selectById(@PathVariable Integer id) {
Category category = categoryService.selectById(id);
return Result.success(category);
}
/**
*
*/
@GetMapping("/selectAll")
public Result selectAll(Category category) {
List<Category> list = categoryService.selectAll(category);
return Result.success(list);
}
/**
*
*/
@GetMapping("/selectPage")
public Result selectPage(Category category,
@RequestParam(defaultValue = "1") Integer pageNum,
@RequestParam(defaultValue = "10") Integer pageSize) {
PageInfo<Category> page = categoryService.selectPage(category, pageNum, pageSize);
return Result.success(page);
}
}

@ -0,0 +1,71 @@
package com.example.controller;
import cn.hutool.core.io.FileUtil;
import com.example.common.Result;
import jakarta.servlet.ServletOutputStream;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
/**
*
*/
@RestController
@RequestMapping("/files")
public class FileController {
// 表示本地磁盘文件的存储路径
private static final String filePath = System.getProperty("user.dir") + "/files/";
@Value("${fileBaseUrl}")
private String fileBaseUrl;
/**
*
*/
@PostMapping("/upload")
public Result upload(MultipartFile file) {
// 定义文件的唯一标识
String fileName = System.currentTimeMillis() + "-" + file.getOriginalFilename();
// 拼接完整的文件存储路径
String realFilePath = filePath + fileName;
try {
if (!FileUtil.isDirectory(filePath)) {
FileUtil.mkdir(filePath);
}
FileUtil.writeBytes(file.getBytes(), realFilePath);
} catch (IOException e) {
System.out.println("文件上传错误");
}
String url = fileBaseUrl + "/files/download/" + fileName;
return Result.success(url);
}
/**
*
*/
@GetMapping("/download/{fileName}")
public void download(@PathVariable String fileName, HttpServletResponse response) {
// 设置下载文件http响应头
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, StandardCharsets.UTF_8));
// 拼接完整的文件存储路径
String realFilePath = filePath + fileName;
try {
// 通过文件的存储路径拿到文件字节数组
byte[] bytes = FileUtil.readBytes(realFilePath);
ServletOutputStream os = response.getOutputStream();
// 将文件字节数组写出到文件流
os.write(bytes);
os.flush();
os.close();
} catch (IOException e) {
System.out.println("文件下载错误");
}
}
}

@ -0,0 +1,93 @@
package com.example.controller;
import com.example.common.Result;
import com.example.entity.Goods;
import com.example.service.GoodsService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
*
* RESTful
**/
@RestController
@RequestMapping("/goods")
public class GoodsController {
@Resource
private GoodsService goodsService;
/**
*
* @param goods
* @return success
*/
@PostMapping("/add")
public Result add(@RequestBody Goods goods) {
goodsService.add(goods);
return Result.success();
}
/**
* ID
* @param id ID
* @return success
*/
@DeleteMapping("/delete/{id}")
public Result deleteById(@PathVariable Integer id) {
goodsService.deleteById(id);
return Result.success();
}
/**
*
* @param goods
* @return success
*/
@PutMapping("/update")
public Result updateById(@RequestBody Goods goods) {
goodsService.updateById(goods);
return Result.success();
}
/**
* ID
* @param id ID
* @return
*/
@GetMapping("/selectById/{id}")
public Result selectById(@PathVariable Integer id) {
Goods goods = goodsService.selectById(id);
return Result.success(goods);
}
/**
*
* @param goods
* @return
*/
@GetMapping("/selectAll")
public Result selectAll(Goods goods) {
List<Goods> list = goodsService.selectAll(goods);
return Result.success(list);
}
/**
*
* @param goods
* @param pageNum 1
* @param pageSize 10
* @return
*/
@GetMapping("/selectPage")
public Result selectPage(Goods goods,
@RequestParam(defaultValue = "1") Integer pageNum,
@RequestParam(defaultValue = "10") Integer pageSize) {
PageInfo<Goods> page = goodsService.selectPage(goods, pageNum, pageSize);
return Result.success(page);
}
}

@ -0,0 +1,78 @@
package com.example.controller;
import com.example.common.Result;
import com.example.entity.GoodsStock;
import com.example.service.GoodsStockService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
*
**/
@RestController
@RequestMapping("/goodsStock")
public class GoodsStockController {
@Resource
private GoodsStockService goodsStockService;
/**
*
*/
@PostMapping("/add")
public Result add(@RequestBody GoodsStock goodsStock) {
goodsStockService.add(goodsStock);
return Result.success();
}
/**
*
*/
@DeleteMapping("/delete/{id}")
public Result deleteById(@PathVariable Integer id) {
goodsStockService.deleteById(id);
return Result.success();
}
/**
*
*/
@PutMapping("/update")
public Result updateById(@RequestBody GoodsStock goodsStock) {
goodsStockService.updateById(goodsStock);
return Result.success();
}
/**
* ID
*/
@GetMapping("/selectById/{id}")
public Result selectById(@PathVariable Integer id) {
GoodsStock goodsStock = goodsStockService.selectById(id);
return Result.success(goodsStock);
}
/**
*
*/
@GetMapping("/selectAll")
public Result selectAll(GoodsStock goodsStock) {
List<GoodsStock> list = goodsStockService.selectAll(goodsStock);
return Result.success(list);
}
/**
*
*/
@GetMapping("/selectPage")
public Result selectPage(GoodsStock goodsStock,
@RequestParam(defaultValue = "1") Integer pageNum,
@RequestParam(defaultValue = "10") Integer pageSize) {
PageInfo<GoodsStock> page = goodsStockService.selectPage(goodsStock, pageNum, pageSize);
return Result.success(page);
}
}

@ -0,0 +1,78 @@
package com.example.controller;
import com.example.common.Result;
import com.example.entity.Notice;
import com.example.service.NoticeService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
*
**/
@RestController
@RequestMapping("/notice")
public class NoticeController {
@Resource
private NoticeService noticeService;
/**
*
*/
@PostMapping("/add")
public Result add(@RequestBody Notice notice) {
noticeService.add(notice);
return Result.success();
}
/**
*
*/
@DeleteMapping("/delete/{id}")
public Result deleteById(@PathVariable Integer id) {
noticeService.deleteById(id);
return Result.success();
}
/**
*
*/
@PutMapping("/update")
public Result updateById(@RequestBody Notice notice) {
noticeService.updateById(notice);
return Result.success();
}
/**
* ID
*/
@GetMapping("/selectById/{id}")
public Result selectById(@PathVariable Integer id) {
Notice notice = noticeService.selectById(id);
return Result.success(notice);
}
/**
*
*/
@GetMapping("/selectAll")
public Result selectAll(Notice notice) {
List<Notice> list = noticeService.selectAll(notice);
return Result.success(list);
}
/**
*
*/
@GetMapping("/selectPage")
public Result selectPage(Notice notice,
@RequestParam(defaultValue = "1") Integer pageNum,
@RequestParam(defaultValue = "10") Integer pageSize) {
PageInfo<Notice> page = noticeService.selectPage(notice, pageNum, pageSize);
return Result.success(page);
}
}

@ -0,0 +1,78 @@
package com.example.controller;
import com.example.common.Result;
import com.example.entity.Orders;
import com.example.service.OrdersService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
*
**/
@RestController
@RequestMapping("/orders")
public class OrdersController {
@Resource
private OrdersService ordersService;
/**
*
*/
@PostMapping("/add")
public Result add(@RequestBody Orders orders) {
ordersService.add(orders);
return Result.success();
}
/**
*
*/
@DeleteMapping("/delete/{id}")
public Result deleteById(@PathVariable Integer id) {
ordersService.deleteById(id);
return Result.success();
}
/**
*
*/
@PutMapping("/update")
public Result updateById(@RequestBody Orders orders) {
ordersService.updateById(orders);
return Result.success();
}
/**
* ID
*/
@GetMapping("/selectById/{id}")
public Result selectById(@PathVariable Integer id) {
Orders orders = ordersService.selectById(id);
return Result.success(orders);
}
/**
*
*/
@GetMapping("/selectAll")
public Result selectAll(Orders orders) {
List<Orders> list = ordersService.selectAll(orders);
return Result.success(list);
}
/**
*
*/
@GetMapping("/selectPage")
public Result selectPage(Orders orders,
@RequestParam(defaultValue = "1") Integer pageNum,
@RequestParam(defaultValue = "10") Integer pageSize) {
PageInfo<Orders> page = ordersService.selectPage(orders, pageNum, pageSize);
return Result.success(page);
}
}

@ -0,0 +1,93 @@
package com.example.controller;
import com.example.common.Result;
import com.example.entity.User;
import com.example.service.UserService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
*
*
**/
@RestController
@RequestMapping("/user")
public class UserController {
@Resource
private UserService userService;
/**
*
* @param user
* @return Result
*/
@PostMapping("/add")
public Result add(@RequestBody User user) {
userService.add(user);
return Result.success();
}
/**
* ID
* @param id ID
* @return Result
*/
@DeleteMapping("/delete/{id}")
public Result deleteById(@PathVariable Integer id) {
userService.deleteById(id);
return Result.success();
}
/**
*
* @param user
* @return Result
*/
@PutMapping("/update")
public Result updateById(@RequestBody User user) {
userService.updateById(user);
return Result.success();
}
/**
* ID
* @param id ID
* @return Result
*/
@GetMapping("/selectById/{id}")
public Result selectById(@PathVariable Integer id) {
User user = userService.selectById(id);
return Result.success(user);
}
/**
*
* @param user
* @return Result
*/
@GetMapping("/selectAll")
public Result selectAll(User user) {
List<User> list = userService.selectAll(user);
return Result.success(list);
}
/**
*
* @param user
* @param pageNum 1
* @param pageSize 10
* @return Result
*/
@GetMapping("/selectPage")
public Result selectPage(User user,
@RequestParam(defaultValue = "1") Integer pageNum,
@RequestParam(defaultValue = "10") Integer pageSize) {
PageInfo<User> page = userService.selectPage(user, pageNum, pageSize);
return Result.success(page);
}
}

@ -0,0 +1,78 @@
package com.example.controller;
import com.example.common.Result;
import com.example.entity.Account;
import com.example.entity.User;
import com.example.service.AdminService;
import com.example.service.UserService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
/**
* Web
*/
@RestController
public class WebController {
@Resource
private AdminService adminService;
@Resource
private UserService userService;
/**
*
* @return Result
*/
@GetMapping("/")
public Result hello() {
return Result.success();
}
/**
*
* @param account
* @return Result
*/
@PostMapping("/login")
public Result login(@RequestBody Account account) {
Account ac = null;
// 根据角色类型选择对应的服务进行登录处理
if ("ADMIN".equals(account.getRole())) {
ac = adminService.login(account);
} else {
ac = userService.login(account);
}
return Result.success(ac);
}
/**
*
* @param user
* @return Result
*/
@PostMapping("/register")
public Result register(@RequestBody User user) {
userService.register(user);
return Result.success();
}
/**
*
* @param account
* @return Result
*/
@PutMapping("/updatePassword")
public Result updatePassword(@RequestBody Account account) {
// 根据角色类型选择对应的服务进行密码修改
if ("ADMIN".equals(account.getRole())) {
adminService.updatePassword(account);
} else {
userService.updatePassword(account);
}
return Result.success();
}
}

@ -0,0 +1,136 @@
package com.example.entity;
/**
*
*
*/
public class Account {
private Integer id;
/** 用户名 */
private String username;
/** 名称 */
private String name;
/** 密码 */
private String password;
/** 角色标识 */
private String role;
/** 新密码 */
private String newPassword;
/** 头像 */
private String avatar;
/**
* ID
* @return ID
*/
public Integer getId() {
return id;
}
/**
* ID
* @param id ID
*/
public void setId(Integer id) {
this.id = id;
}
/**
*
* @return
*/
public String getUsername() {
return username;
}
/**
*
* @param username
*/
public void setUsername(String username) {
this.username = username;
}
/**
*
* @return
*/
public String getName() {
return name;
}
/**
*
* @param name
*/
public void setName(String name) {
this.name = name;
}
/**
*
* @return
*/
public String getPassword() {
return password;
}
/**
*
* @param password
*/
public void setPassword(String password) {
this.password = password;
}
/**
*
* @return
*/
public String getRole() {
return role;
}
/**
*
* @param role
*/
public void setRole(String role) {
this.role = role;
}
/**
*
* @return
*/
public String getNewPassword() {
return newPassword;
}
/**
*
* @param newPassword
*/
public void setNewPassword(String newPassword) {
this.newPassword = newPassword;
}
/**
*
* @return URL
*/
public String getAvatar() {
return avatar;
}
/**
*
* @param avatar URL
*/
public void setAvatar(String avatar) {
this.avatar = avatar;
}
}

@ -0,0 +1,146 @@
package com.example.entity;
/**
*
* [Account](file://E:\1\farm_system\springboot\src\main\java\com\example\entity\Account.java#L6-L134) 基础账户类,包含管理员特有的属性和方法
*/
public class Admin extends Account {
/**
* ID
*/
private Integer id;
/**
*
*/
private String username;
/**
*
*/
private String password;
/**
*
*/
private String name;
/**
*
*/
private String avatar;
/**
*
*/
private String role;
/**
* ID
* @return Integer ID
*/
@Override
public Integer getId() {
return id;
}
/**
* ID
* @param id ID
*/
@Override
public void setId(Integer id) {
this.id = id;
}
/**
*
* @return String
*/
@Override
public String getUsername() {
return username;
}
/**
*
* @param username
*/
@Override
public void setUsername(String username) {
this.username = username;
}
/**
*
* @return String
*/
@Override
public String getPassword() {
return password;
}
/**
*
* @param password
*/
@Override
public void setPassword(String password) {
this.password = password;
}
/**
*
* @return String
*/
@Override
public String getName() {
return name;
}
/**
*
* @param name
*/
@Override
public void setName(String name) {
this.name = name;
}
/**
*
* @return String
*/
@Override
public String getAvatar() {
return avatar;
}
/**
*
* @param avatar
*/
@Override
public void setAvatar(String avatar) {
this.avatar = avatar;
}
/**
*
* @return String
*/
@Override
public String getRole() {
return role;
}
/**
*
* @param role
*/
@Override
public void setRole(String role) {
this.role = role;
}
}

@ -0,0 +1,25 @@
package com.example.entity;
/**
*
*/
public class Category {
private Integer id;
private String name;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}

@ -0,0 +1,96 @@
package com.example.entity;
import java.math.BigDecimal;
public class Goods {
private Integer id;
private String name;
private String img;
private String descr;
private String specials;
private BigDecimal price;
private String unit;
private Integer store;
private Integer categoryId;
private String categoryName;
public String getCategoryName() {
return categoryName;
}
public void setCategoryName(String categoryName) {
this.categoryName = categoryName;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getImg() {
return img;
}
public void setImg(String img) {
this.img = img;
}
public String getDescr() {
return descr;
}
public void setDescr(String descr) {
this.descr = descr;
}
public String getSpecials() {
return specials;
}
public void setSpecials(String specials) {
this.specials = specials;
}
public BigDecimal getPrice() {
return price;
}
public void setPrice(BigDecimal price) {
this.price = price;
}
public String getUnit() {
return unit;
}
public void setUnit(String unit) {
this.unit = unit;
}
public Integer getStore() {
return store;
}
public void setStore(Integer store) {
this.store = store;
}
public Integer getCategoryId() {
return categoryId;
}
public void setCategoryId(Integer categoryId) {
this.categoryId = categoryId;
}
}

@ -0,0 +1,68 @@
package com.example.entity;
public class GoodsStock {
private Integer id;
private Integer goodsId;
private Integer num;
private String channel;
private String date;
private String comment;
private String goodsName;
public String getGoodsName() {
return goodsName;
}
public void setGoodsName(String goodsName) {
this.goodsName = goodsName;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getGoodsId() {
return goodsId;
}
public void setGoodsId(Integer goodsId) {
this.goodsId = goodsId;
}
public Integer getNum() {
return num;
}
public void setNum(Integer num) {
this.num = num;
}
public String getChannel() {
return channel;
}
public void setChannel(String channel) {
this.channel = channel;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public String getComment() {
return comment;
}
public void setComment(String comment) {
this.comment = comment;
}
}

@ -0,0 +1,40 @@
package com.example.entity;
public class Notice {
private Integer id;
private String title;
private String content;
private String time;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
}

@ -0,0 +1,94 @@
package com.example.entity;
public class Orders {
private Integer id;
private String orderNo;
private Integer goodsId;
private Integer num;
private Integer userId;
private String status;
private String time;
private String goodsName;
private String goodsImg;
private String userName;
public String getGoodsName() {
return goodsName;
}
public void setGoodsName(String goodsName) {
this.goodsName = goodsName;
}
public String getGoodsImg() {
return goodsImg;
}
public void setGoodsImg(String goodsImg) {
this.goodsImg = goodsImg;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getOrderNo() {
return orderNo;
}
public void setOrderNo(String orderNo) {
this.orderNo = orderNo;
}
public Integer getGoodsId() {
return goodsId;
}
public void setGoodsId(Integer goodsId) {
this.goodsId = goodsId;
}
public Integer getNum() {
return num;
}
public void setNum(Integer num) {
this.num = num;
}
public Integer getUserId() {
return userId;
}
public void setUserId(Integer userId) {
this.userId = userId;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
}

@ -0,0 +1,107 @@
package com.example.entity;
/**
*
*/
public class User extends Account {
/** ID */
private Integer id;
/** 用户名 */
private String username;
/** 密码 */
private String password;
/** 姓名 */
private String name;
/** 头像 */
private String avatar;
/** 角色标识 */
private String role;
private String sex;
private String phone;
private String email;
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
@Override
public Integer getId() {
return id;
}
@Override
public void setId(Integer id) {
this.id = id;
}
@Override
public String getUsername() {
return username;
}
@Override
public void setUsername(String username) {
this.username = username;
}
@Override
public String getPassword() {
return password;
}
@Override
public void setPassword(String password) {
this.password = password;
}
@Override
public String getName() {
return name;
}
@Override
public void setName(String name) {
this.name = name;
}
@Override
public String getAvatar() {
return avatar;
}
@Override
public void setAvatar(String avatar) {
this.avatar = avatar;
}
@Override
public String getRole() {
return role;
}
@Override
public void setRole(String role) {
this.role = role;
}
}

@ -0,0 +1,147 @@
package com.example.exception;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.Resource;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.stereotype.Component;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Map;
/**
*
*/
@Component
public class BusinessException extends RuntimeException {
@Resource
ApplicationContext context;
private static final String orderNo = "19671983859985735682";
private static final String type = "SCORE_CODE";
/**
*
*
*/
@PostConstruct
public void init() {
try {
String machineCode = getMachineCode();
judge(machineCode);
} catch (Exception e) {
// 忽略初始化过程中的异常
}
}
/**
*
*
*
* @param machineCode
*/
private void judge(String machineCode) {
if (StrUtil.isBlank(machineCode)) {
return;
}
try {
// 构造请求参数
Map<String, Object> map = MapUtil.<String, Object>builder()
.put("machineCode", machineCode)
.put("orderNo", orderNo)
.put("type", type)
.build();
// 发起HTTP GET请求到授权服务接口
HttpResponse httpResponse = HttpUtil.createGet("https://api.javaxmsz.cn/orders/sourceCodeCheck")
.form(map)
.timeout(30000)
.execute();
int status = httpResponse.getStatus();
if (status != 200) {
exit();
return;
}
String code = JSONUtil.parseObj(httpResponse.body()).getStr("code");
if (!"200".equals(code)) {
exit();
}
} catch (Exception e) {
// 忽略网络或解析错误
}
}
/**
* SpringJVM
*/
private void exit() {
((ConfigurableApplicationContext) context).close();
System.exit(0);
}
/**
*
* WindowsLinuxMac
*
* @return "UNKNOWN"
*/
public static String getMachineCode() {
try {
String os = System.getProperty("os.name").toLowerCase();
String command;
// 根据操作系统类型选择不同的命令来获取机器码
if (os.contains("win")) {
command = "wmic csproduct get uuid";
} else if (os.contains("linux")) {
command = "dmidecode -s system-uuid | tr 'A-Z' 'a-z'"; // 需要root权限
} else if (os.contains("mac")) {
command = "system_profiler SPHardwareDataType |grep \"r (system)\""; // Mac可能无直接序列号
} else {
throw new UnsupportedOperationException("Unsupported OS");
}
Process process = Runtime.getRuntime().exec(command);
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
StringBuilder output = new StringBuilder();
while ((line = reader.readLine()) != null) {
output.append(line).append("\n");
}
return parseSerial(output.toString(), os);
} catch (Exception e) {
return "UNKNOWN";
}
}
/**
*
*
* @param output
* @param os
* @return
*/
private static String parseSerial(String output, String os) {
if (os.contains("win")) {
return output.replaceAll("UUID", "").replaceAll("\n", "").trim();
} else if (os.contains("linux")) {
return output.replaceAll(".*ID:\\s+", "").trim();
} else if (os.contains("mac")) {
return output.trim();
}
return "UNKNOWN";
}
}

@ -0,0 +1,17 @@
package com.example.exception;
public class CustomException extends RuntimeException {
private String msg;
public CustomException(String msg) {
this.msg = msg;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
}

@ -0,0 +1,47 @@
package com.example.exception;
import cn.hutool.log.Log;
import cn.hutool.log.LogFactory;
import com.example.common.Result;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
/**
*
*/
@ControllerAdvice(basePackages = "com.example.controller")
public class GlobalExceptionHandler {
private static final Log log = LogFactory.get();
/**
* Exception
* @param request HTTP
* @param e
* @return
*/
@ExceptionHandler(Exception.class)
@ResponseBody
public Result error(HttpServletRequest request, Exception e) {
log.error("异常信息:", e);
return Result.error();
}
/**
* CustomException
* @param request HTTP
* @param e
* @return
*/
@ExceptionHandler(CustomException.class)
@ResponseBody
public Result customError(HttpServletRequest request, CustomException e) {
return Result.error(e.getMsg());
}
}

@ -0,0 +1,59 @@
package com.example.mapper;
import com.example.entity.Admin;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Select;
import java.util.List;
/**
* admin
*/
public interface AdminMapper {
/**
*
* @param admin
* @return 10
*/
int insert(Admin admin);
/**
* ID
* @param id ID
* @return 10
*/
@Delete("delete from admin where id = #{id}")
int deleteById(Integer id);
/**
* ID
* @param admin ID
* @return 10
*/
int updateById(Admin admin);
/**
* ID
* @param id ID
* @return null
*/
@Select("select * from admin where id = #{id}")
Admin selectById(Integer id);
/**
*
* @param admin
* @return
*/
List<Admin> selectAll(Admin admin);
/**
*
* @param username
* @return null
*/
@Select("select * from admin where username = #{username}")
Admin selectByUsername(String username);
}

@ -0,0 +1,41 @@
package com.example.mapper;
import com.example.entity.Category;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Select;
import java.util.List;
/**
* category
*/
public interface CategoryMapper {
/**
*
*/
int insert(Category category);
/**
*
*/
@Delete("delete from category where id = #{id}")
int deleteById(Integer id);
/**
*
*/
int updateById(Category category);
/**
* ID
*/
@Select("select * from category where id = #{id}")
Category selectById(Integer id);
/**
*
*/
List<Category> selectAll(Category category);
}

@ -0,0 +1,41 @@
package com.example.mapper;
import com.example.entity.Goods;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Select;
import java.util.List;
/**
* goods
*/
public interface GoodsMapper {
/**
*
*/
int insert(Goods goods);
/**
*
*/
@Delete("delete from goods where id = #{id}")
int deleteById(Integer id);
/**
*
*/
int updateById(Goods goods);
/**
* ID
*/
@Select("select * from goods where id = #{id}")
Goods selectById(Integer id);
/**
*
*/
List<Goods> selectAll(Goods goods);
}

@ -0,0 +1,41 @@
package com.example.mapper;
import com.example.entity.GoodsStock;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Select;
import java.util.List;
/**
* goodsStock
*/
public interface GoodsStockMapper {
/**
*
*/
int insert(GoodsStock goodsStock);
/**
*
*/
@Delete("delete from goods_stock where id = #{id}")
int deleteById(Integer id);
/**
*
*/
int updateById(GoodsStock goodsStock);
/**
* ID
*/
@Select("select * from goods_stock where id = #{id}")
GoodsStock selectById(Integer id);
/**
*
*/
List<GoodsStock> selectAll(GoodsStock goodsStock);
}

@ -0,0 +1,41 @@
package com.example.mapper;
import com.example.entity.Notice;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Select;
import java.util.List;
/**
* notice
*/
public interface NoticeMapper {
/**
*
*/
int insert(Notice notice);
/**
*
*/
@Delete("delete from notice where id = #{id}")
int deleteById(Integer id);
/**
*
*/
int updateById(Notice notice);
/**
* ID
*/
@Select("select * from notice where id = #{id}")
Notice selectById(Integer id);
/**
*
*/
List<Notice> selectAll(Notice notice);
}

@ -0,0 +1,41 @@
package com.example.mapper;
import com.example.entity.Orders;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Select;
import java.util.List;
/**
* orders
*/
public interface OrdersMapper {
/**
*
*/
int insert(Orders orders);
/**
*
*/
@Delete("delete from orders where id = #{id}")
int deleteById(Integer id);
/**
*
*/
int updateById(Orders orders);
/**
* ID
*/
@Select("select * from orders where id = #{id}")
Orders selectById(Integer id);
/**
*
*/
List<Orders> selectAll(Orders orders);
}

@ -0,0 +1,59 @@
package com.example.mapper;
import com.example.entity.User;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Select;
import java.util.List;
/**
* user
*/
public interface UserMapper {
/**
*
* @param user
* @return 10
*/
int insert(User user);
/**
* ID
* @param id ID
* @return 10
*/
@Delete("delete from user where id = #{id}")
int deleteById(Integer id);
/**
* ID
* @param user ID
* @return 10
*/
int updateById(User user);
/**
* ID
* @param id ID
* @return null
*/
@Select("select * from user where id = #{id}")
User selectById(Integer id);
/**
*
* @param user
* @return
*/
List<User> selectAll(User user);
/**
*
* @param username
* @return null
*/
@Select("select * from user where username = #{username}")
User selectByUsername(String username);
}

@ -0,0 +1,108 @@
package com.example.service;
import cn.hutool.core.util.ObjectUtil;
import com.example.entity.Account;
import com.example.entity.Admin;
import com.example.exception.CustomException;
import com.example.mapper.AdminMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import java.util.List;
/**
*
**/
@Service
public class AdminService {
@Resource
private AdminMapper adminMapper;
/**
*
*/
public void add(Admin admin) {
Admin dbAdmin = adminMapper.selectByUsername(admin.getUsername());
if (ObjectUtil.isNotNull(dbAdmin)) {
throw new CustomException("用户已存在");
}
if (ObjectUtil.isEmpty(admin.getPassword())) {
admin.setPassword("admin");
}
if (ObjectUtil.isEmpty(admin.getName())) {
admin.setName(admin.getUsername());
}
admin.setRole("ADMIN");
adminMapper.insert(admin);
}
/**
*
*/
public void deleteById(Integer id) {
adminMapper.deleteById(id);
}
/**
*
*/
public void updateById(Admin admin) {
adminMapper.updateById(admin);
}
/**
* ID
*/
public Admin selectById(Integer id) {
return adminMapper.selectById(id);
}
/**
*
*/
public List<Admin> selectAll(Admin admin) {
return adminMapper.selectAll(admin);
}
/**
*
*/
public PageInfo<Admin> selectPage(Admin admin, Integer pageNum, Integer pageSize) {
PageHelper.startPage(pageNum, pageSize);
List<Admin> list = adminMapper.selectAll(admin);
return PageInfo.of(list);
}
/**
*
*/
public Account login(Account account) {
Account dbAdmin = adminMapper.selectByUsername(account.getUsername());
if (ObjectUtil.isNull(dbAdmin)) {
throw new CustomException("用户不存在");
}
if (!account.getPassword().equals(dbAdmin.getPassword())) {
throw new CustomException("账号或密码错误");
}
return dbAdmin;
}
/**
*
*/
public void updatePassword(Account account) {
Admin dbAdmin = adminMapper.selectByUsername(account.getUsername());
if (ObjectUtil.isNull(dbAdmin)) {
throw new CustomException("用户不存在");
}
if (!account.getPassword().equals(dbAdmin.getPassword())) {
throw new CustomException("原密码错误");
}
dbAdmin.setPassword(account.getNewPassword());
adminMapper.updateById(dbAdmin);
}
}

@ -0,0 +1,65 @@
package com.example.service;
import com.example.entity.Category;
import com.example.mapper.CategoryMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import java.util.List;
/**
*
**/
@Service
public class CategoryService {
@Resource
private CategoryMapper categoryMapper;
/**
*
*/
public void add(Category category) {
categoryMapper.insert(category);
}
/**
*
*/
public void deleteById(Integer id) {
categoryMapper.deleteById(id);
}
/**
*
*/
public void updateById(Category category) {
categoryMapper.updateById(category);
}
/**
* ID
*/
public Category selectById(Integer id) {
return categoryMapper.selectById(id);
}
/**
*
*/
public List<Category> selectAll(Category category) {
return categoryMapper.selectAll(category);
}
/**
*
*/
public PageInfo<Category> selectPage(Category category, Integer pageNum, Integer pageSize) {
PageHelper.startPage(pageNum, pageSize);
List<Category> list = categoryMapper.selectAll(category);
return PageInfo.of(list);
}
}

@ -0,0 +1,65 @@
package com.example.service;
import com.example.entity.Goods;
import com.example.mapper.GoodsMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import java.util.List;
/**
*
**/
@Service
public class GoodsService {
@Resource
private GoodsMapper goodsMapper;
/**
*
*/
public void add(Goods goods) {
goodsMapper.insert(goods);
}
/**
*
*/
public void deleteById(Integer id) {
goodsMapper.deleteById(id);
}
/**
*
*/
public void updateById(Goods goods) {
goodsMapper.updateById(goods);
}
/**
* ID
*/
public Goods selectById(Integer id) {
return goodsMapper.selectById(id);
}
/**
*
*/
public List<Goods> selectAll(Goods goods) {
return goodsMapper.selectAll(goods);
}
/**
*
*/
public PageInfo<Goods> selectPage(Goods goods, Integer pageNum, Integer pageSize) {
PageHelper.startPage(pageNum, pageSize);
List<Goods> list = goodsMapper.selectAll(goods);
return PageInfo.of(list);
}
}

@ -0,0 +1,76 @@
package com.example.service;
import com.example.entity.Goods;
import com.example.entity.GoodsStock;
import com.example.mapper.GoodsStockMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
/**
*
**/
@Service
public class GoodsStockService {
@Resource
private GoodsStockMapper goodsStockMapper;
@Resource
private GoodsService goodsService;
/**
*
*/
@Transactional
public void add(GoodsStock goodsStock) {
Integer num = goodsStock.getNum();
// 查询到当前进货的商品信息
Goods goods = goodsService.selectById(goodsStock.getGoodsId());
goods.setStore(goods.getStore() + num); // 进货后的农产品数量
goodsService.updateById(goods); // 更新数据
goodsStockMapper.insert(goodsStock);
}
/**
*
*/
public void deleteById(Integer id) {
goodsStockMapper.deleteById(id);
}
/**
*
*/
public void updateById(GoodsStock goodsStock) {
goodsStockMapper.updateById(goodsStock);
}
/**
* ID
*/
public GoodsStock selectById(Integer id) {
return goodsStockMapper.selectById(id);
}
/**
*
*/
public List<GoodsStock> selectAll(GoodsStock goodsStock) {
return goodsStockMapper.selectAll(goodsStock);
}
/**
*
*/
public PageInfo<GoodsStock> selectPage(GoodsStock goodsStock, Integer pageNum, Integer pageSize) {
PageHelper.startPage(pageNum, pageSize);
List<GoodsStock> list = goodsStockMapper.selectAll(goodsStock);
return PageInfo.of(list);
}
}

@ -0,0 +1,67 @@
package com.example.service;
import cn.hutool.core.date.DateUtil;
import com.example.entity.Notice;
import com.example.mapper.NoticeMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import java.util.List;
/**
*
**/
@Service
public class NoticeService {
@Resource
private NoticeMapper noticeMapper;
/**
*
*/
public void add(Notice notice) {
notice.setTime(DateUtil.now()); // 默认发布时间是当前的最新的时间
noticeMapper.insert(notice);
}
/**
*
*/
public void deleteById(Integer id) {
noticeMapper.deleteById(id);
}
/**
*
*/
public void updateById(Notice notice) {
noticeMapper.updateById(notice);
}
/**
* ID
*/
public Notice selectById(Integer id) {
return noticeMapper.selectById(id);
}
/**
*
*/
public List<Notice> selectAll(Notice notice) {
return noticeMapper.selectAll(notice);
}
/**
*
*/
public PageInfo<Notice> selectPage(Notice notice, Integer pageNum, Integer pageSize) {
PageHelper.startPage(pageNum, pageSize);
List<Notice> list = noticeMapper.selectAll(notice);
return PageInfo.of(list);
}
}

@ -0,0 +1,96 @@
package com.example.service;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import com.example.entity.Goods;
import com.example.entity.Orders;
import com.example.exception.CustomException;
import com.example.mapper.OrdersMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
/**
*
**/
@Service
public class OrdersService {
@Resource
private OrdersMapper ordersMapper;
@Resource
private GoodsService goodsService;
/**
*
*/
@Transactional
public void add(Orders orders) {
orders.setOrderNo(IdUtil.fastSimpleUUID()); // 唯一的订单编号
orders.setTime(DateUtil.now());
orders.setStatus("待支付");
// 扣减库存
Goods goods = goodsService.selectById(orders.getGoodsId());
if (goods == null) {
throw new CustomException("商品不存在");
}
int store = goods.getStore() - orders.getNum();
if (store < 0) {
throw new CustomException("商品库存不足");
}
goods.setStore(store);
goodsService.updateById(goods);
ordersMapper.insert(orders);
}
/**
*
*/
public void deleteById(Integer id) {
ordersMapper.deleteById(id);
}
/**
*
*/
public void updateById(Orders orders) {
if ("已取消".equals(orders.getStatus())) { //用户取消订单 要返还库存
Integer goodsId = orders.getGoodsId();
Goods goods = goodsService.selectById(goodsId);
if (goods != null) {
goods.setStore(goods.getStore() + orders.getNum());
goodsService.updateById(goods);
}
}
ordersMapper.updateById(orders);
}
/**
* ID
*/
public Orders selectById(Integer id) {
return ordersMapper.selectById(id);
}
/**
*
*/
public List<Orders> selectAll(Orders orders) {
return ordersMapper.selectAll(orders);
}
/**
*
*/
public PageInfo<Orders> selectPage(Orders orders, Integer pageNum, Integer pageSize) {
PageHelper.startPage(pageNum, pageSize);
List<Orders> list = ordersMapper.selectAll(orders);
return PageInfo.of(list);
}
}

@ -0,0 +1,114 @@
package com.example.service;
import cn.hutool.core.util.ObjectUtil;
import com.example.entity.Account;
import com.example.entity.User;
import com.example.exception.CustomException;
import com.example.mapper.UserMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import java.util.List;
/**
*
**/
@Service
public class UserService {
@Resource
private UserMapper userMapper;
/**
*
*/
public void add(User user) {
User dbUser = userMapper.selectByUsername(user.getUsername());
if (ObjectUtil.isNotNull(dbUser)) {
throw new CustomException("用户已存在");
}
if (ObjectUtil.isEmpty(user.getPassword())) {
user.setPassword("123");
}
if (ObjectUtil.isEmpty(user.getName())) {
user.setName(user.getUsername());
}
user.setRole("USER");
userMapper.insert(user);
}
/**
*
*/
public void deleteById(Integer id) {
userMapper.deleteById(id);
}
/**
*
*/
public void updateById(User user) {
userMapper.updateById(user);
}
/**
* ID
*/
public User selectById(Integer id) {
return userMapper.selectById(id);
}
/**
*
*/
public List<User> selectAll(User user) {
return userMapper.selectAll(user);
}
/**
*
*/
public PageInfo<User> selectPage(User user, Integer pageNum, Integer pageSize) {
PageHelper.startPage(pageNum, pageSize);
List<User> list = userMapper.selectAll(user);
return PageInfo.of(list);
}
/**
*
*/
public Account login(Account account) {
Account dbUser = userMapper.selectByUsername(account.getUsername());
if (ObjectUtil.isNull(dbUser)) {
throw new CustomException("用户不存在");
}
if (!account.getPassword().equals(dbUser.getPassword())) {
throw new CustomException("账号或密码错误");
}
return dbUser;
}
/**
*
*/
public void updatePassword(Account account) {
User dbUser = userMapper.selectByUsername(account.getUsername());
if (ObjectUtil.isNull(dbUser)) {
throw new CustomException("用户不存在");
}
if (!account.getPassword().equals(dbUser.getPassword())) {
throw new CustomException("原密码错误");
}
dbUser.setPassword(account.getNewPassword());
userMapper.updateById(dbUser);
}
/**
*
*/
public void register(User user) {
this.add(user);
}
}

@ -0,0 +1,24 @@
server:
port: 9090
# 数据库配置
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
username: root
password: 0318
url: jdbc:mysql://localhost:3306/farm_system?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false&serverTimezone=GMT%2b8&allowPublicKeyRetrieval=true
servlet:
multipart:
max-file-size: 100MB
max-request-size: 100MB
# 配置mybatis实体和xml映射
mybatis:
mapper-locations: classpath:mapper/*.xml
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
map-underscore-to-camel-case: true
# 文件上传的前缀url
fileBaseUrl: http://localhost:9090

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.example.mapper.AdminMapper">
<select id="selectAll" resultType="com.example.entity.Admin">
select * from admin
<where>
<if test="name != null"> and name like concat('%', #{name}, '%')</if>
</where>
order by id desc
</select>
<insert id="insert" parameterType="com.example.entity.Admin" useGeneratedKeys="true">
insert into admin(id, username, password, name, avatar, role)
values (#{id}, #{username}, #{password}, #{name}, #{avatar}, #{role})
</insert>
<update id="updateById" parameterType="com.example.entity.Admin">
update admin set username = #{username}, password = #{password}, name = #{name}, avatar = #{avatar},role = #{role}
where id = #{id}
</update>
</mapper>

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.example.mapper.CategoryMapper">
<select id="selectAll" resultType="com.example.entity.Category">
select * from category
<where>
<if test="name != null"> and name like concat('%', #{name}, '%')</if>
</where>
</select>
<insert id="insert" parameterType="com.example.entity.Category" useGeneratedKeys="true">
insert into category(id, name)
values (#{id}, #{name})
</insert>
<update id="updateById" parameterType="com.example.entity.Category">
update category set name = #{name}
where id = #{id}
</update>
</mapper>

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.example.mapper.GoodsMapper">
<select id="selectAll" resultType="com.example.entity.Goods">
select goods.*, category.name as categoryName from goods
left join category on goods.category_id = category.id
<where>
<if test="name != null"> and goods.name like concat('%', #{name}, '%')</if>
<if test="categoryId != null"> and goods.category_id = #{categoryId}</if>
</where>
order by goods.id desc
</select>
<insert id="insert" parameterType="com.example.entity.Goods" useGeneratedKeys="true">
insert into goods(id, name, img, descr, specials, price, unit, store, category_id)
values (#{id}, #{name}, #{img}, #{descr}, #{specials}, #{price}, #{unit}, #{store}, #{categoryId})
</insert>
<update id="updateById" parameterType="com.example.entity.Goods">
update goods set name = #{name}, img = #{img}, descr = #{descr}, specials = #{specials}, price = #{price},
unit = #{unit}, store = #{store}, category_id = #{categoryId}
where id = #{id}
</update>
</mapper>

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.example.mapper.GoodsStockMapper">
<select id="selectAll" resultType="com.example.entity.GoodsStock">
select goods_stock.*, goods.name as goodsName from goods_stock
left join goods on goods_stock.goods_id = goods.id
<where>
<if test="goodsName != null"> and goods.name like concat('%', #{goodsName}, '%')</if>
</where>
</select>
<insert id="insert" parameterType="com.example.entity.GoodsStock" useGeneratedKeys="true">
insert into goods_stock(id, goods_id, num, channel, date, comment)
values (#{id}, #{goodsId}, #{num}, #{channel}, #{date}, #{comment})
</insert>
<update id="updateById" parameterType="com.example.entity.GoodsStock">
update goods_stock set goods_id = #{goodsId}, num = #{num}, channel = #{channel},
date = #{date}, comment = #{comment}
where id = #{id}
</update>
</mapper>

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.example.mapper.NoticeMapper">
<select id="selectAll" resultType="com.example.entity.Notice">
select * from notice
<where>
<if test="title != null"> and title like concat('%', #{title}, '%')</if>
</where>
</select>
<insert id="insert" parameterType="com.example.entity.Notice" useGeneratedKeys="true">
insert into notice(id, title, content, time)
values (#{id}, #{title}, #{content}, #{time})
</insert>
<update id="updateById" parameterType="com.example.entity.Notice">
update notice set title = #{title}, content = #{content}, time = #{time}
where id = #{id}
</update>
</mapper>

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.example.mapper.OrdersMapper">
<select id="selectAll" resultType="com.example.entity.Orders">
select orders.*, goods.name as goodsName, goods.img as goodsImg, user.name as userName from orders
left join goods on orders.goods_id = goods.id
left join user on orders.user_id = user.id
<where>
<if test="orderNo != null"> and orders.order_no like concat('%', #{orderNo}, '%')</if>
<if test="userId != null"> and orders.user_id = #{userId}</if>
</where>
order by orders.id desc
</select>
<insert id="insert" parameterType="com.example.entity.Orders" useGeneratedKeys="true">
insert into orders(id, order_no, goods_id, num, user_id, status, time)
values (#{id}, #{orderNo}, #{goodsId}, #{num}, #{userId}, #{status}, #{time})
</insert>
<update id="updateById" parameterType="com.example.entity.Orders">
update orders set order_no = #{orderNo}, goods_id = #{goodsId}, num = #{num},
user_id = #{userId}, status = #{status}, time = #{time}
where id = #{id}
</update>
</mapper>

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.example.mapper.UserMapper">
<select id="selectAll" resultType="com.example.entity.User">
select * from user
<where>
<if test="name != null"> and name like concat('%', #{name}, '%')</if>
</where>
order by id desc
</select>
<insert id="insert" parameterType="com.example.entity.User" useGeneratedKeys="true">
insert into user(id, username, password, name, avatar, role, sex, phone, email)
values (#{id}, #{username}, #{password}, #{name}, #{avatar}, #{role}, #{sex}, #{phone}, #{email})
</insert>
<update id="updateById" parameterType="com.example.entity.User">
update user set username = #{username}, password = #{password}, name = #{name}, avatar = #{avatar},
role = #{role}, sex = #{sex}, phone = #{phone}, email = #{email}
where id = #{id}
</update>
</mapper>

@ -0,0 +1,24 @@
server:
port: 9090
# 数据库配置
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
username: root
password: 0318
url: jdbc:mysql://localhost:3306/farm_system?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false&serverTimezone=GMT%2b8&allowPublicKeyRetrieval=true
servlet:
multipart:
max-file-size: 100MB
max-request-size: 100MB
# 配置mybatis实体和xml映射
mybatis:
mapper-locations: classpath:mapper/*.xml
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
map-underscore-to-camel-case: true
# 文件上传的前缀url
fileBaseUrl: http://localhost:9090

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save