@ -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&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false&serverTimezone=GMT%2b8&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,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>
|
||||
|
After Width: | Height: | Size: 126 KiB |
|
After Width: | Height: | Size: 200 KiB |
|
After Width: | Height: | Size: 66 KiB |
|
After Width: | Height: | Size: 78 KiB |
|
After Width: | Height: | Size: 142 KiB |
|
After Width: | Height: | Size: 83 KiB |
|
After Width: | Height: | Size: 249 KiB |
|
After Width: | Height: | Size: 113 KiB |
@ -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,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,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,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,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,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,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
|
||||