wohuibaohuni 3 months ago
parent d434e344f4
commit 805b96272c

@ -0,0 +1,115 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>springboot</artifactId>
<version>0.0.1-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.9</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--mysql-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20210307</version>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.4.6</version>
<exclusions>
<exclusion>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.8.18</version>
</dependency>
<dependency>
<groupId>com.auth0</groupId>
<artifactId>java-jwt</artifactId>
<version>4.3.0</version>
</dependency>
<!-- 引入验证码依赖 -->
<dependency>
<groupId>com.github.whvcse</groupId>
<artifactId>easy-captcha</artifactId>
<version>1.6.2</version>
</dependency>
<!-- poi依赖 -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>5.2.3</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>public</id>
<name>aliyun nexus</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
</repository>
</repositories>
</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;
import org.springframework.scheduling.annotation.EnableScheduling;
@SpringBootApplication
@MapperScan("com.example.mapper")
@EnableScheduling
public class SpringbootApplication {
public static void main(String[] args) {
SpringApplication.run(SpringbootApplication.class, args);
}
}

@ -0,0 +1,9 @@
package com.example.common;
public interface Constants {
String TOKEN = "token";
String USER_DEFAULT_PASSWORD = "123";
}

@ -0,0 +1,75 @@
package com.example.common;
import com.example.common.enums.ResultCodeEnum;
public class Result {
private String code;
private String msg;
private Object data;
private Result(Object data) {
this.data = data;
}
public Result() {
}
public static Result success() {
Result tResult = new Result();
tResult.setCode(ResultCodeEnum.SUCCESS.code);
tResult.setMsg(ResultCodeEnum.SUCCESS.msg);
return tResult;
}
public static Result success(Object data) {
Result tResult = new Result (data);
tResult.setCode(ResultCodeEnum.SUCCESS.code);
tResult.setMsg(ResultCodeEnum.SUCCESS.msg);
return tResult;
}
public static Result error() {
Result tResult = new Result();
tResult.setCode(ResultCodeEnum.SYSTEM_ERROR.code);
tResult.setMsg(ResultCodeEnum.SYSTEM_ERROR.msg);
return tResult;
}
public static Result error(String code, String msg) {
Result tResult = new Result();
tResult.setCode(code);
tResult.setMsg(msg);
return tResult;
}
public static Result error(ResultCodeEnum resultCodeEnum) {
Result tResult = new Result();
tResult.setCode(resultCodeEnum.code);
tResult.setMsg(resultCodeEnum.msg);
return tResult;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public Object getData() {
return data;
}
public void setData(Object data) {
this.data = data;
}
}

@ -0,0 +1,25 @@
package com.example.common.config;
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 {
@Bean
public CorsFilter corsFilter() {
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
CorsConfiguration corsConfiguration = new CorsConfiguration();
corsConfiguration.addAllowedOrigin("*"); // 1 设置访问源地址
corsConfiguration.addAllowedHeader("*"); // 2 设置访问源请求头
corsConfiguration.addAllowedMethod("*"); // 3 设置访问源请求方法
source.registerCorsConfiguration("/**", corsConfiguration); // 4 对接口配置跨域设置
return new CorsFilter(source);
}
}

@ -0,0 +1,77 @@
package com.example.common.config;
import cn.hutool.core.util.ObjectUtil;
import com.auth0.jwt.JWT;
import com.auth0.jwt.JWTVerifier;
import com.auth0.jwt.algorithms.Algorithm;
import com.auth0.jwt.exceptions.JWTVerificationException;
import com.example.common.Constants;
import com.example.common.enums.ResultCodeEnum;
import com.example.common.enums.RoleEnum;
import com.example.entity.Account;
import com.example.exception.CustomException;
import com.example.service.AdminService;
import com.example.service.StaffService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* jwt
*/
@Component
public class JwtInterceptor implements HandlerInterceptor {
private static final Logger log = LoggerFactory.getLogger(JwtInterceptor.class);
@Resource
private AdminService adminService;
@Resource
private StaffService staffService;
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
// 1. 从http请求的header中获取token
String token = request.getHeader(Constants.TOKEN);
if (ObjectUtil.isEmpty(token)) {
// 如果没拿到,从参数里再拿一次
token = request.getParameter(Constants.TOKEN);
}
// 2. 开始执行认证
if (ObjectUtil.isEmpty(token)) {
throw new CustomException(ResultCodeEnum.TOKEN_INVALID_ERROR);
}
Account account = null;
try {
// 解析token获取存储的数据
String userRole = JWT.decode(token).getAudience().get(0);
String userId = userRole.split("-")[0];
String role = userRole.split("-")[1];
// 根据userId查询数据库
if (RoleEnum.ADMIN.name().equals(role)) {
account = adminService.selectById(Integer.valueOf(userId));
} else if (RoleEnum.STAFF.name().equals(role)) {
account = staffService.selectById(Integer.valueOf(userId));
}
} catch (Exception e) {
throw new CustomException(ResultCodeEnum.TOKEN_CHECK_ERROR);
}
if (ObjectUtil.isNull(account)) {
throw new CustomException(ResultCodeEnum.USER_NOT_EXIST_ERROR);
}
try {
// 用户密码加签验证 token
JWTVerifier jwtVerifier = JWT.require(Algorithm.HMAC256(account.getPassword())).build();
jwtVerifier.verify(token); // 验证token
} catch (JWTVerificationException e) {
throw new CustomException(ResultCodeEnum.TOKEN_CHECK_ERROR);
}
return true;
}
}

@ -0,0 +1,30 @@
package com.example.common.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import javax.annotation.Resource;
@Configuration
public class WebConfig implements WebMvcConfigurer {
@Resource
private JwtInterceptor jwtInterceptor;
// 加自定义拦截器JwtInterceptor设置拦截规则
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(jwtInterceptor).addPathPatterns("/**")
.excludePathPatterns("/")
.excludePathPatterns("/login")
.excludePathPatterns("/register")
.excludePathPatterns("/getValidateCode")
.excludePathPatterns("/files/**")
.excludePathPatterns("/supplier/export")
.excludePathPatterns("/customer/export")
.excludePathPatterns("/goods/export")
.excludePathPatterns("/api/chat")
;
}
}

@ -0,0 +1,30 @@
package com.example.common.enums;
public enum ResultCodeEnum {
SUCCESS("200", "成功"),
PARAM_ERROR("400", "参数异常"),
TOKEN_INVALID_ERROR("401", "无效的token"),
TOKEN_CHECK_ERROR("401", "token验证失败请重新登录"),
PARAM_LOST_ERROR("4001", "参数缺失"),
SYSTEM_ERROR("500", "系统异常"),
USER_EXIST_ERROR("5001", "用户名已存在"),
USER_NOT_LOGIN("5002", "用户未登录"),
USER_ACCOUNT_ERROR("5003", "账号或密码错误"),
USER_NOT_EXIST_ERROR("5004", "用户不存在"),
PARAM_PASSWORD_ERROR("5005", "原密码输入错误"),
VALIDATE_CODE_ERROR("5006", "验证码错误"),
NO_AUTH("5007", "账号被禁用"),
DATA_IMPORT_ERROR("5007", "数据导入错误"),
GOODS_NUM_LIMIT("5007", "库存不足"),
;
public String code;
public String msg;
ResultCodeEnum(String code, String msg) {
this.code = code;
this.msg = msg;
}
}

@ -0,0 +1,8 @@
package com.example.common.enums;
public enum RoleEnum {
// 管理员
ADMIN,
// 员工
STAFF,
}

@ -0,0 +1,86 @@
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 org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
/**
*
**/
@RestController
@RequestMapping("/admin")
public class AdminController {
@Resource
private AdminService adminService;
/**
*
*/
@PostMapping("/add")
public Result add(@RequestBody Admin admin) {
adminService.add(admin);
return Result.success();
}
/**
*
*/
@DeleteMapping("/delete/{id}")
public Result deleteById(@PathVariable Integer id) {
adminService.deleteById(id);
return Result.success();
}
/**
*
*/
@DeleteMapping("/delete/batch")
public Result deleteBatch(@RequestBody List<Integer> ids) {
adminService.deleteBatch(ids);
return Result.success();
}
/**
*
*/
@PutMapping("/update")
public Result updateById(@RequestBody Admin admin) {
adminService.updateById(admin);
return Result.success();
}
/**
* ID
*/
@GetMapping("/selectById/{id}")
public Result selectById(@PathVariable Integer id) {
Admin admin = adminService.selectById(id);
return Result.success(admin);
}
/**
*
*/
@GetMapping("/selectAll")
public Result selectAll(Admin admin ) {
List<Admin> list = adminService.selectAll(admin);
return Result.success(list);
}
/**
*
*/
@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,86 @@
package com.example.controller;
import com.example.common.Result;
import com.example.entity.Back;
import com.example.service.BackService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
/**
* 退
**/
@RestController
@RequestMapping("/back")
public class BackController {
@Resource
private BackService backService;
/**
*
*/
@PostMapping("/add")
public Result add(@RequestBody Back back) {
backService.add(back);
return Result.success();
}
/**
*
*/
@DeleteMapping("/delete/{id}")
public Result deleteById(@PathVariable Integer id) {
backService.deleteById(id);
return Result.success();
}
/**
*
*/
@DeleteMapping("/delete/batch")
public Result deleteBatch(@RequestBody List<Integer> ids) {
backService.deleteBatch(ids);
return Result.success();
}
/**
*
*/
@PutMapping("/update")
public Result updateById(@RequestBody Back back) {
backService.updateById(back);
return Result.success();
}
/**
* ID
*/
@GetMapping("/selectById/{id}")
public Result selectById(@PathVariable Integer id) {
Back back = backService.selectById(id);
return Result.success(back);
}
/**
*
*/
@GetMapping("/selectAll")
public Result selectAll(Back back) {
List<Back> list = backService.selectAll(back);
return Result.success(list);
}
/**
*
*/
@GetMapping("/selectPage")
public Result selectPage(Back back,
@RequestParam(defaultValue = "1") Integer pageNum,
@RequestParam(defaultValue = "10") Integer pageSize) {
PageInfo<Back> page = backService.selectPage(back, pageNum, pageSize);
return Result.success(page);
}
}

@ -0,0 +1,71 @@
//package com.example.controller;
//
//import org.json.JSONObject;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.http.*;
//import org.springframework.web.bind.annotation.*;
//import org.springframework.web.client.RestTemplate;
//
//import javax.annotation.PostConstruct;
//import javax.servlet.http.HttpSession;
//import java.util.logging.Level;
//import java.util.logging.Logger;
//
//@RestController
//@RequestMapping("/api/chat")
//@CrossOrigin
//public class ChatController {
// private static final Logger LOGGER = Logger.getLogger(ChatController.class.getName());
//
// private String apiKey = "sk-2afc18092ea24c938020a4d5f1f9f91a";
//
// private String appId = "1d2b00751a914efd84ea4b354fffd962";
//
// private final RestTemplate restTemplate;
// private String apiUrl;
//
// public ChatController() {
// this.restTemplate = new RestTemplate();
// }
//
// @PostConstruct
// private void init() {
// // 使用appId构建完整的API URL
// this.apiUrl = "https://dashscope.aliyuncs.com/api/v1/apps/" + appId + "/completion";
// }
//
// @PostMapping
// public ResponseEntity<?> chat(@RequestParam String prompt, HttpSession session) {
// try {
// String sessionId = (String) session.getAttribute("chatSessionId");
//
// JSONObject requestBody = new JSONObject();
// JSONObject input = new JSONObject();
// input.put("prompt", prompt);
// if (sessionId != null) {
// input.put("session_id", sessionId);
// }
// requestBody.put("input", input);
// requestBody.put("parameters", new JSONObject());
//
// HttpHeaders headers = new HttpHeaders();
// headers.setContentType(MediaType.APPLICATION_JSON);
// headers.set("Authorization", "Bearer " + apiKey);
//
// HttpEntity<String> entity = new HttpEntity<>(requestBody.toString(), headers);
//
// ResponseEntity<String> response = restTemplate.exchange(
// apiUrl,
// HttpMethod.POST,
// entity,
// String.class
// );
//
// return ResponseEntity.ok(response.getBody());
// } catch (Exception e) {
// LOGGER.log(Level.SEVERE, "聊天请求处理失败", e);
// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
// .body("{\"error\":\"服务器错误: " + e.getMessage() + "\"}");
// }
// }
//}

@ -0,0 +1,137 @@
package com.example.controller;
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;
import com.example.common.Result;
import com.example.common.enums.ResultCodeEnum;
import com.example.entity.Customer;
import com.example.service.CustomerService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.List;
/**
*
**/
@RestController
@RequestMapping("/customer")
public class CustomerController {
@Resource
private CustomerService customerService;
/**
*
*/
@PostMapping("/add")
public Result add(@RequestBody Customer customer) {
customerService.add(customer);
return Result.success();
}
/**
*
*/
@DeleteMapping("/delete/{id}")
public Result deleteById(@PathVariable Integer id) {
customerService.deleteById(id);
return Result.success();
}
/**
*
*/
@DeleteMapping("/delete/batch")
public Result deleteBatch(@RequestBody List<Integer> ids) {
customerService.deleteBatch(ids);
return Result.success();
}
/**
*
*/
@PutMapping("/update")
public Result updateById(@RequestBody Customer customer) {
customerService.updateById(customer);
return Result.success();
}
/**
* ID
*/
@GetMapping("/selectById/{id}")
public Result selectById(@PathVariable Integer id) {
Customer customer = customerService.selectById(id);
return Result.success(customer);
}
/**
*
*/
@GetMapping("/selectAll")
public Result selectAll(Customer customer) {
List<Customer> list = customerService.selectAll(customer);
return Result.success(list);
}
/**
*
*/
@GetMapping("/selectPage")
public Result selectPage(Customer customer,
@RequestParam(defaultValue = "1") Integer pageNum,
@RequestParam(defaultValue = "10") Integer pageSize) {
PageInfo<Customer> page = customerService.selectPage(customer, pageNum, pageSize);
return Result.success(page);
}
/**
*
*/
@GetMapping("/export")
public void exportData(HttpServletResponse response) throws IOException {
ExcelWriter writer = ExcelUtil.getWriter(true);
List<Customer> list = customerService.selectAll(null);
writer.write(list, true);
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("客户信息表", "UTF-8") + ".xlsx");
ServletOutputStream outputStream = response.getOutputStream();
writer.flush(outputStream, true);
outputStream.flush();
writer.close();
outputStream.close();
}
/**
*
*
* @param file excel
* @return
*/
@PostMapping("/import")
public Result importData(MultipartFile file) throws IOException {
ExcelReader reader = ExcelUtil.getReader(file.getInputStream());
List<Customer> list = reader.readAll(Customer.class);
// 写入数据到数据库
try {
for (Customer customer : list) {
customerService.add(customer);
}
} catch (Exception e) {
System.err.println(e.getMessage());
return Result.error(ResultCodeEnum.DATA_IMPORT_ERROR);
}
return Result.success();
}
}

@ -0,0 +1,94 @@
package com.example.controller;
import com.example.common.Result;
import com.example.entity.Department;
import com.example.service.DepartmentService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
/**
*
*/
@RestController
@RequestMapping("/department")
public class DepartmentController {
@Resource
private DepartmentService departmentService;
/**
*
*/
@PostMapping("/add")
public Result add(@RequestBody Department department) {
departmentService.add(department);
return Result.success();
}
/**
*
*/
@DeleteMapping("/delete/{id}")
public Result deleteById(@PathVariable Integer id) {
departmentService.deleteById(id);
return Result.success();
}
/**
*
*/
@DeleteMapping("/delete/batch")
public Result deleteBatch(@RequestBody List<Integer> ids) {
departmentService.deleteBatch(ids);
return Result.success();
}
/**
*
*/
@PutMapping("/update")
public Result updateById(@RequestBody Department department) {
departmentService.updateById(department);
return Result.success();
}
/**
* ID
*/
@GetMapping("/selectById/{id}")
public Result selectById(@PathVariable Integer id) {
Department department = departmentService.selectById(id);
return Result.success(department);
}
/**
*
*/
@GetMapping("/selectAll")
public Result selectAll(Department department ) {
List<Department> list = departmentService.selectAll(department);
return Result.success(list);
}
/**
*
*/
@GetMapping("/selectTree")
public Result selectTree() {
List<Department> list = departmentService.selectTree();
return Result.success(list);
}
/**
*
*/
@GetMapping("/selectPage")
public Result selectPage(Department department,
@RequestParam(defaultValue = "1") Integer pageNum,
@RequestParam(defaultValue = "10") Integer pageSize) {
PageInfo<Department> page = departmentService.selectPage(department, pageNum, pageSize);
return Result.success(page);
}
}

@ -0,0 +1,95 @@
package com.example.controller;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.core.util.StrUtil;
import com.example.common.Result;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.util.List;
/**
*
*/
@RestController
@RequestMapping("/files")
public class FileController {
// 文件上传存储路径
private static final String filePath = System.getProperty("user.dir") + "/files/";
@Value("${server.port:9090}")
private String port;
@Value("${ip:localhost}")
private String ip;
/**
*
*/
@PostMapping("/upload")
public Result upload(MultipartFile file) {
String flag;
synchronized (FileController.class) {
flag = System.currentTimeMillis() + "";
ThreadUtil.sleep(1L);
}
String fileName = file.getOriginalFilename();
try {
if (!FileUtil.isDirectory(filePath)) {
FileUtil.mkdir(filePath);
}
// 文件存储形式:时间戳-文件名
FileUtil.writeBytes(file.getBytes(), filePath + flag + "-" + fileName); // ***/manager/files/1697438073596-avatar.png
System.out.println(fileName + "--上传成功");
} catch (Exception e) {
System.err.println(fileName + "--文件上传失败");
}
String http = "http://" + ip + ":" + port + "/files/";
return Result.success(http + flag + "-" + fileName); // http://localhost:9090/files/1697438073596-avatar.png
}
/**
*
*
* @param flag
* @param response
*/
@GetMapping("/{flag}") // 1697438073596-avatar.png
public void avatarPath(@PathVariable String flag, HttpServletResponse response) {
OutputStream os;
try {
if (StrUtil.isNotEmpty(flag)) {
response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(flag, "UTF-8"));
response.setContentType("application/octet-stream");
byte[] bytes = FileUtil.readBytes(filePath + flag);
os = response.getOutputStream();
os.write(bytes);
os.flush();
os.close();
}
} catch (Exception e) {
System.out.println("文件下载失败");
}
}
/**
*
*
* @param flag
*/
@DeleteMapping("/{flag}")
public void delFile(@PathVariable String flag) {
FileUtil.del(filePath + flag);
System.out.println("删除文件" + flag + "成功");
}
}

@ -0,0 +1,137 @@
package com.example.controller;
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;
import com.example.common.Result;
import com.example.common.enums.ResultCodeEnum;
import com.example.entity.Goods;
import com.example.service.GoodsService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.List;
/**
*
**/
@RestController
@RequestMapping("/goods")
public class GoodsController {
@Resource
private GoodsService goodsService;
/**
*
*/
@PostMapping("/add")
public Result add(@RequestBody Goods goods) {
goodsService.add(goods);
return Result.success();
}
/**
*
*/
@DeleteMapping("/delete/{id}")
public Result deleteById(@PathVariable Integer id) {
goodsService.deleteById(id);
return Result.success();
}
/**
*
*/
@DeleteMapping("/delete/batch")
public Result deleteBatch(@RequestBody List<Integer> ids) {
goodsService.deleteBatch(ids);
return Result.success();
}
/**
*
*/
@PutMapping("/update")
public Result updateById(@RequestBody Goods goods) {
goodsService.updateById(goods);
return Result.success();
}
/**
* ID
*/
@GetMapping("/selectById/{id}")
public Result selectById(@PathVariable Integer id) {
Goods goods = goodsService.selectById(id);
return Result.success(goods);
}
/**
*
*/
@GetMapping("/selectAll")
public Result selectAll(Goods goods) {
List<Goods> list = goodsService.selectAll(goods);
return Result.success(list);
}
/**
*
*/
@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);
}
/**
*
*/
@GetMapping("/export")
public void exportData(HttpServletResponse response) throws IOException {
ExcelWriter writer = ExcelUtil.getWriter(true);
List<Goods> list = goodsService.selectAll(null);// 查询出当前User表的所有数据
writer.write(list, true);
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("商品信息表", "UTF-8") + ".xlsx");
ServletOutputStream outputStream = response.getOutputStream();
writer.flush(outputStream, true);
outputStream.flush();
writer.close();
outputStream.close();
}
/**
*
*
* @param file excel
* @return
*/
@PostMapping("/import")
public Result importData(MultipartFile file) throws IOException {
ExcelReader reader = ExcelUtil.getReader(file.getInputStream());
List<Goods> list = reader.readAll(Goods.class);
// 写入数据到数据库
try {
for (Goods goods : list) {
goodsService.add(goods);
}
} catch (Exception e) {
System.err.println(e.getMessage());
return Result.error(ResultCodeEnum.DATA_IMPORT_ERROR);
}
return Result.success();
}
}

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

@ -0,0 +1,86 @@
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 org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
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();
}
/**
*
*/
@DeleteMapping("/delete/batch")
public Result deleteBatch(@RequestBody List<Integer> ids) {
noticeService.deleteBatch(ids);
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,86 @@
package com.example.controller;
import com.example.common.Result;
import com.example.entity.SaleBack;
import com.example.service.SaleBackService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
/**
*
**/
@RestController
@RequestMapping("/saleBack")
public class SaleBackController {
@Resource
private SaleBackService saleBackService;
/**
*
*/
@PostMapping("/add")
public Result add(@RequestBody SaleBack saleBack) {
saleBackService.add(saleBack);
return Result.success();
}
/**
*
*/
@DeleteMapping("/delete/{id}")
public Result deleteById(@PathVariable Integer id) {
saleBackService.deleteById(id);
return Result.success();
}
/**
*
*/
@DeleteMapping("/delete/batch")
public Result deleteBatch(@RequestBody List<Integer> ids) {
saleBackService.deleteBatch(ids);
return Result.success();
}
/**
*
*/
@PutMapping("/update")
public Result updateById(@RequestBody SaleBack saleBack) {
saleBackService.updateById(saleBack);
return Result.success();
}
/**
* ID
*/
@GetMapping("/selectById/{id}")
public Result selectById(@PathVariable Integer id) {
SaleBack saleBack = saleBackService.selectById(id);
return Result.success(saleBack);
}
/**
*
*/
@GetMapping("/selectAll")
public Result selectAll(SaleBack saleBack) {
List<SaleBack> list = saleBackService.selectAll(saleBack);
return Result.success(list);
}
/**
*
*/
@GetMapping("/selectPage")
public Result selectPage(SaleBack saleBack,
@RequestParam(defaultValue = "1") Integer pageNum,
@RequestParam(defaultValue = "10") Integer pageSize) {
PageInfo<SaleBack> page = saleBackService.selectPage(saleBack, pageNum, pageSize);
return Result.success(page);
}
}

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

@ -0,0 +1,94 @@
package com.example.controller;
import com.example.common.Result;
import com.example.entity.Account;
import com.example.entity.Staff;
import com.example.service.LogsService;
import com.example.service.StaffService;
import com.example.utils.TokenUtils;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
@RestController
@RequestMapping("/staff")
public class StaffController {
@Resource
private StaffService staffService;
/**
*
*/
@PostMapping("/add")
public Result add(@RequestBody Staff staff) {
staffService.add(staff);
Account currentUser = TokenUtils.getCurrentUser();
LogsService.recordLog("新增员工" + staff.getUsername(), "新增", currentUser.getUsername());
return Result.success();
}
/**
*
*/
@DeleteMapping("/delete/{id}")
public Result deleteById(@PathVariable Integer id) {
Account currentUser = TokenUtils.getCurrentUser();
Staff staff = staffService.selectById(id);
LogsService.recordLog("删除员工" + staff.getUsername(), "删除", currentUser.getUsername());
staffService.deleteById(id);
return Result.success();
}
/**
*
*/
@DeleteMapping("/delete/batch")
public Result deleteBatch(@RequestBody List<Integer> ids) {
staffService.deleteBatch(ids);
return Result.success();
}
/**
*
*/
@PutMapping("/update")
public Result updateById(@RequestBody Staff staff) {
staffService.updateById(staff);
return Result.success();
}
/**
* ID
*/
@GetMapping("/selectById/{id}")
public Result selectById(@PathVariable Integer id) {
Staff staff = staffService.selectById(id);
return Result.success(staff);
}
/**
*
*/
@GetMapping("/selectAll")
public Result selectAll(Staff staff) {
List<Staff> list = staffService.selectAll(staff);
return Result.success(list);
}
/**
*
*/
@GetMapping("/selectPage")
public Result selectPage(Staff staff,
@RequestParam(defaultValue = "1") Integer pageNum,
@RequestParam(defaultValue = "10") Integer pageSize) {
PageInfo<Staff> page = staffService.selectPage(staff, pageNum, pageSize);
return Result.success(page);
}
}

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

@ -0,0 +1,133 @@
package com.example.controller;
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;
import com.example.common.Result;
import com.example.common.enums.ResultCodeEnum;
import com.example.entity.Supplier;
import com.example.service.SupplierService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.List;
/**
*
**/
@RestController
@RequestMapping("/supplier")
public class SupplierController {
@Resource
private SupplierService supplierService;
/**
*
*/
@PostMapping("/add")
public Result add(@RequestBody Supplier supplier) {
supplierService.add(supplier);
return Result.success();
}
/**
*
*/
@DeleteMapping("/delete/{id}")
public Result deleteById(@PathVariable Integer id) {
supplierService.deleteById(id);
return Result.success();
}
/**
*
*/
@DeleteMapping("/delete/batch")
public Result deleteBatch(@RequestBody List<Integer> ids) {
supplierService.deleteBatch(ids);
return Result.success();
}
/**
*
*/
@PutMapping("/update")
public Result updateById(@RequestBody Supplier supplier) {
supplierService.updateById(supplier);
return Result.success();
}
/**
* ID
*/
@GetMapping("/selectById/{id}")
public Result selectById(@PathVariable Integer id) {
Supplier supplier = supplierService.selectById(id);
return Result.success(supplier);
}
/**
*
*/
@GetMapping("/selectAll")
public Result selectAll(Supplier supplier) {
List<Supplier> list = supplierService.selectAll(supplier);
return Result.success(list);
}
/**
*
*/
@GetMapping("/selectPage")
public Result selectPage(Supplier supplier,
@RequestParam(defaultValue = "1") Integer pageNum,
@RequestParam(defaultValue = "10") Integer pageSize) {
PageInfo<Supplier> page = supplierService.selectPage(supplier, pageNum, pageSize);
return Result.success(page);
}
/**
*
*/
@GetMapping("/export")
public void exportData(HttpServletResponse response) throws IOException {
ExcelWriter writer = ExcelUtil.getWriter(true);
List<Supplier> list = supplierService.selectAll(null);
writer.write(list, true);
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("供应商信息表", "UTF-8") + ".xlsx");
ServletOutputStream outputStream = response.getOutputStream();
writer.flush(outputStream, true);
outputStream.flush();
writer.close();
outputStream.close();
}
/**
*
*/
@PostMapping("/import")
public Result importData(MultipartFile file) throws IOException {
ExcelReader reader = ExcelUtil.getReader(file.getInputStream());
List<Supplier> list = reader.readAll(Supplier.class);
// 写入数据到数据库
try {
for (Supplier supplier : list) {
supplierService.add(supplier);
}
} catch (Exception e) {
return Result.error(ResultCodeEnum.DATA_IMPORT_ERROR);
}
return Result.success();
}
}

@ -0,0 +1,241 @@
package com.example.controller;
import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.Dict;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.example.common.Result;
import com.example.common.enums.ResultCodeEnum;
import com.example.common.enums.RoleEnum;
import com.example.entity.Account;
import com.example.entity.Goods;
import com.example.entity.Sale;
import com.example.entity.Stock;
import com.example.exception.CustomException;
import com.example.service.*;
import com.example.utils.TokenUtils;
import com.example.utils.ValidateCodeCache;
import com.example.utils.ValidateCodeProperties;
import com.wf.captcha.GifCaptcha;
import com.wf.captcha.SpecCaptcha;
import com.wf.captcha.base.Captcha;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
/**
*
*/
@RestController
public class WebController {
@Resource
private AdminService adminService;
@Resource
private StaffService staffService;
@Resource
private GoodsService goodsService;
@Resource
StockService stockService;
@Resource
SaleService saleService;
@Autowired
WarnService warnService;
@GetMapping("/")
public Result hello() {
return Result.success("访问成功");
}
@GetMapping("/getValidateCode")
public void getValidateCode(HttpServletRequest request, HttpServletResponse response) {
// 生成验证码
ValidateCodeProperties code = new ValidateCodeProperties();
setHeader(response, code.getType());
Captcha captcha = createCaptcha(code);
// 存储验证码到缓存
ValidateCodeCache.setCache(request.getParameter("key"), captcha.text().toLowerCase());
try {
ServletOutputStream outputStream = response.getOutputStream();
captcha.out(outputStream);
outputStream.flush();
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
throw new CustomException(ResultCodeEnum.VALIDATE_CODE_ERROR);
}
}
/**
*
*/
private Captcha createCaptcha(ValidateCodeProperties code) {
Captcha captcha = null;
if ("gif".equalsIgnoreCase(code.getType())) {
captcha = new GifCaptcha(code.getWidth(), code.getHeight(), code.getLength());
} else {
captcha = new SpecCaptcha(code.getWidth(), code.getHeight(), code.getLength());
}
captcha.setCharType(code.getCharType());
return captcha;
}
/**
*
*/
private void setHeader(HttpServletResponse response, String type) {
if ("gif".equalsIgnoreCase(type)) {
response.setContentType(MediaType.IMAGE_GIF_VALUE);
} else {
response.setContentType(MediaType.IMAGE_PNG_VALUE);
}
response.setHeader(HttpHeaders.PRAGMA, "No-cache");
response.setHeader(HttpHeaders.CACHE_CONTROL, "no-cache");
response.setDateHeader(HttpHeaders.EXPIRES, 0L);
}
/**
*
*/
@PostMapping("/login")
public Result login(@RequestBody Account account) {
if (ObjectUtil.isEmpty(account.getUsername()) || ObjectUtil.isEmpty(account.getPassword())
|| ObjectUtil.isEmpty(account.getRole()) || ObjectUtil.isEmpty(account.getKey())
|| ObjectUtil.isEmpty(account.getCode())) {
return Result.error(ResultCodeEnum.PARAM_LOST_ERROR);
}
// 对验证码进行校验
boolean result = ValidateCodeCache.validateCode(account.getKey(), account.getCode());
if (!result) { // code不存在
return Result.error(ResultCodeEnum.VALIDATE_CODE_ERROR);
}
if (RoleEnum.ADMIN.name().equals(account.getRole())) {
account = adminService.login(account);
} else if (RoleEnum.STAFF.name().equals(account.getRole())) {
account = staffService.login(account);
}
// 记录登录的日志
LogsService.recordLog("用户登录", "登录", account.getUsername());
return Result.success(account);
}
/**
*
*/
@PostMapping("/register")
public Result register(@RequestBody Account account) {
if (StrUtil.isBlank(account.getUsername()) || StrUtil.isBlank(account.getPassword())
|| ObjectUtil.isEmpty(account.getRole())) {
return Result.error(ResultCodeEnum.PARAM_LOST_ERROR);
}
if (RoleEnum.STAFF.name().equals(account.getRole())) {
staffService.register(account);
// 记录登录的日志
LogsService.recordLog("用户注册", "注册", account.getUsername());
}
return Result.success();
}
/**
*
*/
@PutMapping("/updatePassword")
public Result updatePassword(@RequestBody Account account) {
if (StrUtil.isBlank(account.getUsername()) || StrUtil.isBlank(account.getPassword())
|| ObjectUtil.isEmpty(account.getNewPassword())) {
return Result.error(ResultCodeEnum.PARAM_LOST_ERROR);
}
if (RoleEnum.ADMIN.name().equals(account.getRole())) {
adminService.updatePassword(account);
} else if (RoleEnum.STAFF.name().equals(account.getRole())) {
staffService.updatePassword(account);
}
return Result.success();
}
/**
*
*/
@GetMapping("/dataCount")
public Result dataCount() {
List<Goods> goodsList = goodsService.selectAll(null);
List<Stock> stockList = stockService.selectAll(null);
List<Sale> saleList = saleService.selectAll(null);
// 查询商品总库存
Integer store = goodsList.stream().map(Goods::getNum).reduce(Integer::sum).orElse(0);
// 查询商品的总金额
Double money = goodsList.stream().map(goods -> goods.getPrice() * goods.getNum()).reduce(Double::sum).orElse(0D);
// 查询进货数量
Integer stock = stockList.stream().map(Stock::getNum).reduce(Integer::sum).orElse(0);
// 查询销售数量
Integer sale = saleList.stream().map(Sale::getNum).reduce(Integer::sum).orElse(0);
Dict dict = Dict.create().set("store", store).set("money", money).set("stock", stock).set("sale", sale);
return Result.success(dict);
}
/**
*
*/
@GetMapping("/goodsCount")
public Result goodsCount() {
List<Sale> saleList = saleService.selectAll(null);
// 获取最新的一周的数据
Date today = new Date();
// 从8天前到昨天 一周的时间集合
List<DateTime> dateRange = DateUtil.rangeToList(DateUtil.offsetDay(today, -8), DateUtil.offsetDay(today, -1), DateField.DAY_OF_YEAR);
// 排序
dateRange = dateRange.stream().sorted((a, b) -> (int) (a.getTime() - b.getTime())).collect(Collectors.toList());
List<Dict> list = new ArrayList<>();
for (DateTime dateTime : dateRange) {
String dateStr = DateUtil.formatDate(dateTime);// 把 datetime类型的数据转换成字符串
Double sum = saleList.stream().filter(sale -> sale.getTime().contains(dateStr)).map(Sale::getTotal).reduce(Double::sum).orElse(0D);
Dict dict = Dict.create();
dict.set("name", dateStr).set("value", sum);
list.add(dict);
}
return Result.success(list);
}
/**
*
*/
@GetMapping("/storeCount")
public Result storeCount() {
List<Goods> goodsList = goodsService.selectAll(null);
List<Dict> list = new ArrayList<>();
List<String> nameList = goodsList.stream().map(Goods::getName).collect(Collectors.toList());
for (String name : nameList) {
Dict dict = Dict.create();
Integer sum = goodsList.stream().filter(goods -> goods.getName().equals(name)).map(Goods::getNum).reduce(Integer::sum).orElse(0);
dict.set("name", name).set("value", sum);
list.add(dict);
}
return Result.success(list);
}
@GetMapping("/warning")
public Result warning(){
return warnService.warning();
}
}

@ -0,0 +1,122 @@
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;
private String token;
private String key;
private String code;
private Boolean status;
private String departmentName;
public String getDepartmentName() {
return departmentName;
}
public void setDepartmentName(String departmentName) {
this.departmentName = departmentName;
}
public Boolean getStatus() {
return status;
}
public void setStatus(Boolean status) {
this.status = status;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getRole() {
return role;
}
public void setRole(String role) {
this.role = role;
}
public String getNewPassword() {
return newPassword;
}
public void setNewPassword(String newPassword) {
this.newPassword = newPassword;
}
public String getAvatar() {
return avatar;
}
public void setAvatar(String avatar) {
this.avatar = avatar;
}
public String getToken() {
return token;
}
public void setToken(String token) {
this.token = token;
}
}

@ -0,0 +1,103 @@
package com.example.entity;
import java.io.Serializable;
/**
*
*/
public class Admin extends Account implements Serializable {
private static final long serialVersionUID = 1L;
/** ID */
private Integer id;
/** 用户名 */
private String username;
/** 密码 */
private String password;
/** 姓名 */
private String name;
/** 电话 */
private String phone;
/** 邮箱 */
private String email;
/** 头像 */
private String avatar;
/** 角色标识 */
private String role;
@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;
}
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 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,139 @@
package com.example.entity;
import java.io.Serializable;
/**
* 退
*/
public class Back implements Serializable {
private static final long serialVersionUID = 1L;
/** ID */
private Integer id;
/** 供应商ID */
private Integer supplierId;
/** 商品ID */
private Integer goodsId;
/** 支付类型 */
private String payType;
/** 退货时间 */
private String time;
/** 操作人ID */
private String user;
/** 退货数量 */
private Integer num;
/** 商品规格 */
private String unit;
/** 退货价格 */
private Double price;
/** 退货总价格 */
private Double total;
/** 备注 */
private String comment;
private String goodsName;
private String supplierName;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getSupplierId() {
return supplierId;
}
public void setSupplierId(Integer supplierId) {
this.supplierId = supplierId;
}
public Integer getGoodsId() {
return goodsId;
}
public void setGoodsId(Integer goodsId) {
this.goodsId = goodsId;
}
public String getPayType() {
return payType;
}
public void setPayType(String payType) {
this.payType = payType;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
public String getUser() {
return user;
}
public void setUser(String user) {
this.user = user;
}
public Integer getNum() {
return num;
}
public void setNum(Integer num) {
this.num = num;
}
public String getUnit() {
return unit;
}
public void setUnit(String unit) {
this.unit = unit;
}
public Double getPrice() {
return price;
}
public void setPrice(Double price) {
this.price = price;
}
public Double getTotal() {
return total;
}
public void setTotal(Double total) {
this.total = total;
}
public String getComment() {
return comment;
}
public void setComment(String comment) {
this.comment = comment;
}
public String getGoodsName() {
return goodsName;
}
public void setGoodsName(String goodsName) {
this.goodsName = goodsName;
}
public String getSupplierName() {
return supplierName;
}
public void setSupplierName(String supplierName) {
this.supplierName = supplierName;
}
}

@ -0,0 +1,135 @@
package com.example.entity;
import cn.hutool.core.annotation.Alias;
import java.io.Serializable;
/**
*
*/
public class Customer implements Serializable {
private static final long serialVersionUID = 1L;
/** ID */
@Alias("ID")
private Integer id;
/** 客户名称 */
@Alias("客户名称")
private String name;
/** 客户地址 */
@Alias("客户地址")
private String address;
/** 客户电话 */
@Alias("客户电话")
private String tel;
/** 客户邮箱 */
@Alias("客户邮箱")
private String email;
/** 客户邮编 */
@Alias("客户邮编")
private String zipCode;
/** 联系人 */
@Alias("联系人")
private String user;
/** 联系人电话 */
@Alias("联系人电话")
private String phone;
/** 开户银行 */
@Alias("开户银行")
private String bank;
/** 开户行账号 */
@Alias("开户行账号")
private String bankCard;
/** 状态 */
@Alias("状态")
private String status;
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 getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getTel() {
return tel;
}
public void setTel(String tel) {
this.tel = tel;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getZipCode() {
return zipCode;
}
public void setZipCode(String zipCode) {
this.zipCode = zipCode;
}
public String getUser() {
return user;
}
public void setUser(String user) {
this.user = user;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getBank() {
return bank;
}
public void setBank(String bank) {
this.bank = bank;
}
public String getBankCard() {
return bankCard;
}
public void setBankCard(String bankCard) {
this.bankCard = bankCard;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
}

@ -0,0 +1,65 @@
package com.example.entity;
import java.util.List;
/**
*
*/
public class Department {
private Integer id;
private String name;
private String address;
private Integer pid;
private Integer level;
private List<Department> children;
public List<Department> getChildren() {
return children;
}
public void setChildren(List<Department> children) {
this.children = children;
}
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 getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public Integer getPid() {
return pid;
}
public void setPid(Integer pid) {
this.pid = pid;
}
public Integer getLevel() {
return level;
}
public void setLevel(Integer level) {
this.level = level;
}
}

@ -0,0 +1,190 @@
package com.example.entity;
import cn.hutool.core.annotation.Alias;
import java.io.Serializable;
/**
*
*/
public class Goods implements Serializable {
private static final long serialVersionUID = 1L;
/**
* ID
*/
@Alias("ID")
private Integer id;
/**
*
*/
@Alias("商品名称")
private String name;
/**
* ID
*/
@Alias("供应商ID")
private Integer supplierId;
/**
*
*/
@Alias("商品产地")
private String producer;
/**
*
*/
@Alias("商品描述")
private String descr;
/**
*
*/
@Alias("销售价格")
private Double price;
/**
*
*/
@Alias("数量")
private Integer num;
/**
*
*/
@Alias("商品图片")
private String img;
/**
*
*/
@Alias("商品规格")
private String unit;
/**
*
*/
@Alias("包装单位")
private String pack;
/**
*
*/
@Alias("生产批号")
private String productNo;
/**
*
*/
@Alias("批准文号")
private String approveNo;
@Alias("状态")
private String status;
@Alias("供应商名称")
private String supplierName;
public String getSupplierName() {
return supplierName;
}
public void setSupplierName(String supplierName) {
this.supplierName = supplierName;
}
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 Integer getSupplierId() {
return supplierId;
}
public void setSupplierId(Integer supplierId) {
this.supplierId = supplierId;
}
public String getProducer() {
return producer;
}
public void setProducer(String producer) {
this.producer = producer;
}
public String getDescr() {
return descr;
}
public void setDescr(String descr) {
this.descr = descr;
}
public Double getPrice() {
return price;
}
public void setPrice(Double price) {
this.price = price;
}
public String getImg() {
return img;
}
public void setImg(String img) {
this.img = img;
}
public String getPack() {
return pack;
}
public void setPack(String pack) {
this.pack = pack;
}
public String getProductNo() {
return productNo;
}
public void setProductNo(String productNo) {
this.productNo = productNo;
}
public String getApproveNo() {
return approveNo;
}
public void setApproveNo(String approveNo) {
this.approveNo = approveNo;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public Integer getNum() {
return num;
}
public void setNum(Integer num) {
this.num = num;
}
public String getUnit() {
return unit;
}
public void setUnit(String unit) {
this.unit = unit;
}
}

@ -0,0 +1,83 @@
package com.example.entity;
import java.io.Serializable;
/**
*
*/
public class Logs implements Serializable {
private static final long serialVersionUID = 1L;
/**
* ID
*/
private Integer id;
/**
*
*/
private String operation;
/**
*
*/
private String username;
/**
*
*/
private String type;
/**
* IP
*/
private String ip;
/**
*
*/
private String time;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getOperation() {
return operation;
}
public void setOperation(String operation) {
this.operation = operation;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getIp() {
return ip;
}
public void setIp(String ip) {
this.ip = ip;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
}

@ -0,0 +1,62 @@
package com.example.entity;
import java.io.Serializable;
/**
*
*/
public class Notice implements Serializable {
private static final long serialVersionUID = 1L;
/** ID */
private Integer id;
/** 标题 */
private String title;
/** 内容 */
private String content;
/** 创建时间 */
private String time;
/** 创建人 */
private String user;
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;
}
public String getUser() {
return user;
}
public void setUser(String user) {
this.user = user;
}
}

@ -0,0 +1,150 @@
package com.example.entity;
import cn.hutool.core.annotation.Alias;
import java.io.Serializable;
/**
*
*/
public class Sale implements Serializable {
private static final long serialVersionUID = 1L;
/** ID */
@Alias("序号")
private Integer id;
/** 客户ID */
@Alias("客户ID")
private Integer customerId;
/** 商品ID */
@Alias("商品ID")
private Integer goodsId;
/** 支付类型 */
@Alias("支付类型")
private String payType;
/** 销售时间 */
@Alias("销售时间")
private String time;
/** 操作人 */
@Alias("操作人")
private String user;
/** 销售价格 */
@Alias("销售价格")
private Double price;
/** 销售数量 */
@Alias("销售数量")
private Integer num;
/** 商品规格 */
@Alias("商品规格")
private String unit;
/** 备注 */
@Alias("备注")
private String comment;
private String customerName;
private String goodsName;
private Double total;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getCustomerId() {
return customerId;
}
public void setCustomerId(Integer customerId) {
this.customerId = customerId;
}
public Integer getGoodsId() {
return goodsId;
}
public void setGoodsId(Integer goodsId) {
this.goodsId = goodsId;
}
public String getGoodsName() {
return goodsName;
}
public void setGoodsName(String goodsName) {
this.goodsName = goodsName;
}
public String getPayType() {
return payType;
}
public void setPayType(String payType) {
this.payType = payType;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
public String getUser() {
return user;
}
public void setUser(String user) {
this.user = user;
}
public Double getPrice() {
return price;
}
public void setPrice(Double price) {
this.price = price;
}
public Integer getNum() {
return num;
}
public void setNum(Integer num) {
this.num = num;
}
public String getUnit() {
return unit;
}
public void setUnit(String unit) {
this.unit = unit;
}
public String getComment() {
return comment;
}
public void setComment(String comment) {
this.comment = comment;
}
public String getCustomerName() {
return customerName;
}
public void setCustomerName(String customerName) {
this.customerName = customerName;
}
public Double getTotal() {
return total;
}
public void setTotal(Double total) {
this.total = total;
}
}

@ -0,0 +1,139 @@
package com.example.entity;
import java.io.Serializable;
/**
*
*/
public class SaleBack implements Serializable {
private static final long serialVersionUID = 1L;
/** ID */
private Integer id;
/** 客户ID */
private Integer customerId;
/** 商品ID */
private Integer goodsId;
/** 支付类型 */
private String payType;
/** 退货时间 */
private String time;
/** 操作人 */
private String user;
/** 退货单价 */
private Double price;
/** 退货数量 */
private Integer num;
/** 商品规格 */
private String unit;
/** 退货总价 */
private Double total;
/** 备注 */
private String comment;
private String customerName;
private String goodsName;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getCustomerId() {
return customerId;
}
public void setCustomerId(Integer customerId) {
this.customerId = customerId;
}
public Integer getGoodsId() {
return goodsId;
}
public void setGoodsId(Integer goodsId) {
this.goodsId = goodsId;
}
public String getPayType() {
return payType;
}
public void setPayType(String payType) {
this.payType = payType;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
public String getUser() {
return user;
}
public void setUser(String user) {
this.user = user;
}
public Double getPrice() {
return price;
}
public void setPrice(Double price) {
this.price = price;
}
public Integer getNum() {
return num;
}
public void setNum(Integer num) {
this.num = num;
}
public String getUnit() {
return unit;
}
public void setUnit(String unit) {
this.unit = unit;
}
public Double getTotal() {
return total;
}
public void setTotal(Double total) {
this.total = total;
}
public String getComment() {
return comment;
}
public void setComment(String comment) {
this.comment = comment;
}
public String getCustomerName() {
return customerName;
}
public void setCustomerName(String customerName) {
this.customerName = customerName;
}
public String getGoodsName() {
return goodsName;
}
public void setGoodsName(String goodsName) {
this.goodsName = goodsName;
}
}

@ -0,0 +1,126 @@
package com.example.entity;
/**
*
*/
public class Staff extends Account {
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;
private String birth;
private Integer departmentId;
private Boolean status;
private String departmentName;
public String getDepartmentName() {
return departmentName;
}
public void setDepartmentName(String departmentName) {
this.departmentName = departmentName;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAvatar() {
return avatar;
}
public void setAvatar(String avatar) {
this.avatar = avatar;
}
public String getRole() {
return role;
}
public void setRole(String role) {
this.role = role;
}
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;
}
public String getBirth() {
return birth;
}
public void setBirth(String birth) {
this.birth = birth;
}
public Integer getDepartmentId() {
return departmentId;
}
public void setDepartmentId(Integer departmentId) {
this.departmentId = departmentId;
}
public Boolean getStatus() {
return status;
}
public void setStatus(Boolean status) {
this.status = status;
}
}

@ -0,0 +1,142 @@
package com.example.entity;
import java.io.Serializable;
/**
*
*/
public class Stock implements Serializable {
private static final long serialVersionUID = 1L;
/** ID */
private Integer id;
/** 供应商ID */
private Integer supplierId;
/** 商品ID */
private Integer goodsId;
/** 支付类型 */
private String payType;
/** 进货时间 */
private String time;
/** 操作人ID */
private String user;
/** 进货数量 */
private Integer num;
/** 商品规格 */
private String unit;
/** 进货价格 */
private Double price;
/** 进货总价格 */
private Double total;
/** 备注 */
private String comment;
private String supplierName;
private String goodsName;
public String getSupplierName() {
return supplierName;
}
public void setSupplierName(String supplierName) {
this.supplierName = supplierName;
}
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 getSupplierId() {
return supplierId;
}
public void setSupplierId(Integer supplierId) {
this.supplierId = supplierId;
}
public Integer getGoodsId() {
return goodsId;
}
public void setGoodsId(Integer goodsId) {
this.goodsId = goodsId;
}
public String getPayType() {
return payType;
}
public void setPayType(String payType) {
this.payType = payType;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
public String getUser() {
return user;
}
public void setUser(String user) {
this.user = user;
}
public Integer getNum() {
return num;
}
public void setNum(Integer num) {
this.num = num;
}
public String getUnit() {
return unit;
}
public void setUnit(String unit) {
this.unit = unit;
}
public Double getPrice() {
return price;
}
public void setPrice(Double price) {
this.price = price;
}
public Double getTotal() {
return total;
}
public void setTotal(Double total) {
this.total = total;
}
public String getComment() {
return comment;
}
public void setComment(String comment) {
this.comment = comment;
}
}

@ -0,0 +1,135 @@
package com.example.entity;
import cn.hutool.core.annotation.Alias;
import java.io.Serializable;
/**
*
*/
public class Supplier implements Serializable {
private static final long serialVersionUID = 1L;
/** ID */
@Alias("ID")
private Integer id;
/** 供应商名称 */
@Alias("供应商名称")
private String name;
/** 供应商地址 */
@Alias("供应商地址")
private String address;
/** 供应商电话 */
@Alias("供应商电话")
private String tel;
/** 供应商邮箱 */
@Alias("供应商邮箱")
private String email;
/** 邮编 */
@Alias("邮编")
private String zipCode;
/** 联系人 */
@Alias("联系人")
private String user;
/** 联系人电话 */
@Alias("联系人电话")
private String phone;
/** 开户银行 */
@Alias("开户银行")
private String bank;
/** 开户行账号 */
@Alias("开户行账号")
private String bankCard;
/** 状态 */
@Alias("状态")
private String status;
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 getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getTel() {
return tel;
}
public void setTel(String tel) {
this.tel = tel;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getZipCode() {
return zipCode;
}
public void setZipCode(String zipCode) {
this.zipCode = zipCode;
}
public String getUser() {
return user;
}
public void setUser(String user) {
this.user = user;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getBank() {
return bank;
}
public void setBank(String bank) {
this.bank = bank;
}
public String getBankCard() {
return bankCard;
}
public void setBankCard(String bankCard) {
this.bankCard = bankCard;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
}

@ -0,0 +1,35 @@
package com.example.exception;
import com.example.common.enums.ResultCodeEnum;
public class CustomException extends RuntimeException {
private String code;
private String msg;
public CustomException(ResultCodeEnum resultCodeEnum) {
this.code = resultCodeEnum.code;
this.msg = resultCodeEnum.msg;
}
public CustomException(String code, String msg) {
this.code = code;
this.msg = msg;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
}

@ -0,0 +1,31 @@
package com.example.exception;
import cn.hutool.log.Log;
import cn.hutool.log.LogFactory;
import com.example.common.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
@ControllerAdvice(basePackages="com.example.controller")
public class GlobalExceptionHandler {
private static final Log log = LogFactory.get();
//统一异常处理@ExceptionHandler,主要用于Exception
@ExceptionHandler(Exception.class)
@ResponseBody//返回json串
public Result error(HttpServletRequest request, Exception e){
log.error("异常信息:",e);
return Result.error();
}
@ExceptionHandler(CustomException.class)
@ResponseBody//返回json串
public Result customError(HttpServletRequest request, CustomException e){
return Result.error(e.getCode(), e.getMsg());
}
}

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

@ -0,0 +1,36 @@
package com.example.mapper;
import com.example.entity.Back;
import java.util.List;
/**
* back
*/
public interface BackMapper {
/**
*
*/
int insert(Back back);
/**
*
*/
int deleteById(Integer id);
/**
*
*/
int updateById(Back back);
/**
* ID
*/
Back selectById(Integer id);
/**
*
*/
List<Back> selectAll(Back back);
}

@ -0,0 +1,36 @@
package com.example.mapper;
import com.example.entity.Customer;
import java.util.List;
/**
* customer
*/
public interface CustomerMapper {
/**
*
*/
int insert(Customer customer);
/**
*
*/
int deleteById(Integer id);
/**
*
*/
int updateById(Customer customer);
/**
* ID
*/
Customer selectById(Integer id);
/**
*
*/
List<Customer> selectAll(Customer customer);
}

@ -0,0 +1,34 @@
package com.example.mapper;
import com.example.entity.Department;
import java.util.List;
public interface DepartmentMapper {
/**
*
*/
int insert(Department department);
/**
*
*/
int deleteById(Integer id);
/**
*
*/
int updateById(Department department);
/**
* ID
*/
Department selectById(Integer id);
/**
*
*/
List<Department> selectAll(Department department);
}

@ -0,0 +1,36 @@
package com.example.mapper;
import com.example.entity.Goods;
import java.util.List;
/**
* goods
*/
public interface GoodsMapper {
/**
*
*/
int insert(Goods goods);
/**
*
*/
int deleteById(Integer id);
/**
*
*/
int updateById(Goods goods);
/**
* ID
*/
Goods selectById(Integer id);
/**
*
*/
List<Goods> selectAll(Goods goods);
}

@ -0,0 +1,36 @@
package com.example.mapper;
import com.example.entity.Logs;
import java.util.List;
/**
* logs
*/
public interface LogsMapper {
/**
*
*/
int insert(Logs logs);
/**
*
*/
int deleteById(Integer id);
/**
*
*/
int updateById(Logs logs);
/**
* ID
*/
Logs selectById(Integer id);
/**
*
*/
List<Logs> selectAll(Logs logs);
}

@ -0,0 +1,36 @@
package com.example.mapper;
import com.example.entity.Notice;
import java.util.List;
/**
* notice
*/
public interface NoticeMapper {
/**
*
*/
int insert(Notice notice);
/**
*
*/
int deleteById(Integer id);
/**
*
*/
int updateById(Notice notice);
/**
* ID
*/
Notice selectById(Integer id);
/**
*
*/
List<Notice> selectAll(Notice notice);
}

@ -0,0 +1,36 @@
package com.example.mapper;
import com.example.entity.SaleBack;
import java.util.List;
/**
* sale_back
*/
public interface SaleBackMapper {
/**
*
*/
int insert(SaleBack saleBack);
/**
*
*/
int deleteById(Integer id);
/**
*
*/
int updateById(SaleBack saleBack);
/**
* ID
*/
SaleBack selectById(Integer id);
/**
*
*/
List<SaleBack> selectAll(SaleBack saleBack);
}

@ -0,0 +1,36 @@
package com.example.mapper;
import com.example.entity.Sale;
import java.util.List;
/**
* sale
*/
public interface SaleMapper {
/**
*
*/
int insert(Sale sale);
/**
*
*/
int deleteById(Integer id);
/**
*
*/
int updateById(Sale sale);
/**
* ID
*/
Sale selectById(Integer id);
/**
*
*/
List<Sale> selectAll(Sale sale);
}

@ -0,0 +1,35 @@
package com.example.mapper;
import com.example.entity.Staff;
import org.apache.ibatis.annotations.Select;
import java.util.List;
public interface StaffMapper {
/**
*
*/
int insert(Staff staff);
/**
*
*/
int deleteById(Integer id);
/**
*
*/
int updateById(Staff staff);
/**
* ID
*/
Staff selectById(Integer id);
/**
*
*/
List<Staff> selectAll(Staff staff);
Staff selectByUsername(String username);
}

@ -0,0 +1,36 @@
package com.example.mapper;
import com.example.entity.Stock;
import java.util.List;
/**
* stock
*/
public interface StockMapper {
/**
*
*/
int insert(Stock stock);
/**
*
*/
int deleteById(Integer id);
/**
*
*/
int updateById(Stock stock);
/**
* ID
*/
Stock selectById(Integer id);
/**
*
*/
List<Stock> selectAll(Stock stock);
}

@ -0,0 +1,36 @@
package com.example.mapper;
import com.example.entity.Supplier;
import java.util.List;
/**
* supplier
*/
public interface SupplierMapper {
/**
*
*/
int insert(Supplier supplier);
/**
*
*/
int deleteById(Integer id);
/**
*
*/
int updateById(Supplier supplier);
/**
* ID
*/
Supplier selectById(Integer id);
/**
*
*/
List<Supplier> selectAll(Supplier supplier);
}

@ -0,0 +1,17 @@
package com.example.mapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import java.util.List;
import java.util.Map;
@Mapper
public interface WarnMapper {
@Select("SELECT name, num FROM goods WHERE num >= 100")
public List<Map<String, Object>> much();
@Select("SELECT name, num FROM goods WHERE num < 10")
public List<Map<String, Object>> little();
}

@ -0,0 +1,135 @@
package com.example.service;
import cn.hutool.core.util.ObjectUtil;
import com.example.common.Constants;
import com.example.common.enums.ResultCodeEnum;
import com.example.common.enums.RoleEnum;
import com.example.entity.Account;
import com.example.entity.Admin;
import com.example.exception.CustomException;
import com.example.mapper.AdminMapper;
import com.example.utils.TokenUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
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(ResultCodeEnum.USER_EXIST_ERROR);
}
if (ObjectUtil.isEmpty(admin.getPassword())) {
admin.setPassword(Constants.USER_DEFAULT_PASSWORD);
}
if (ObjectUtil.isEmpty(admin.getName())) {
admin.setName(admin.getUsername());
}
admin.setRole(RoleEnum.ADMIN.name());
adminMapper.insert(admin);
}
/**
*
*/
public void deleteById(Integer id) {
adminMapper.deleteById(id);
}
/**
*
*/
public void deleteBatch(List<Integer> ids) {
for (Integer id : ids) {
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(ResultCodeEnum.USER_NOT_EXIST_ERROR);
}
if (!account.getPassword().equals(dbAdmin.getPassword())) {
throw new CustomException(ResultCodeEnum.USER_ACCOUNT_ERROR);
}
// 生成token
String tokenData = dbAdmin.getId() + "-" + RoleEnum.ADMIN.name();
String token = TokenUtils.createToken(tokenData, dbAdmin.getPassword());
dbAdmin.setToken(token);
return dbAdmin;
}
/**
*
*/
public void register(Account account) {
Admin admin = new Admin();
BeanUtils.copyProperties(account, admin);
add(admin);
}
/**
*
*/
public void updatePassword(Account account) {
Admin dbAdmin = adminMapper.selectByUsername(account.getUsername());
if (ObjectUtil.isNull(dbAdmin)) {
throw new CustomException(ResultCodeEnum.USER_NOT_EXIST_ERROR);
}
if (!account.getPassword().equals(dbAdmin.getPassword())) {
throw new CustomException(ResultCodeEnum.PARAM_PASSWORD_ERROR);
}
dbAdmin.setPassword(account.getNewPassword());
adminMapper.updateById(dbAdmin);
}
}

@ -0,0 +1,86 @@
package com.example.service;
import com.example.entity.Account;
import com.example.entity.Back;
import com.example.entity.Goods;
import com.example.mapper.BackMapper;
import com.example.utils.TokenUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
/**
* 退
**/
@Service
public class BackService {
@Resource
private BackMapper backMapper;
@Resource
private GoodsService goodsService;
/**
*
*/
@Transactional
public void add(Back back) {
Goods goods = goodsService.selectById(back.getGoodsId());
goods.setNum(goods.getNum() - back.getNum());
goodsService.updateById(goods);
backMapper.insert(back);
}
/**
*
*/
public void deleteById(Integer id) {
backMapper.deleteById(id);
}
/**
*
*/
public void deleteBatch(List<Integer> ids) {
for (Integer id : ids) {
backMapper.deleteById(id);
}
}
/**
*
*/
public void updateById(Back back) {
backMapper.updateById(back);
}
/**
* ID
*/
public Back selectById(Integer id) {
return backMapper.selectById(id);
}
/**
*
*/
public List<Back> selectAll(Back back) {
return backMapper.selectAll(back);
}
/**
*
*/
public PageInfo<Back> selectPage(Back back, Integer pageNum, Integer pageSize) {
PageHelper.startPage(pageNum, pageSize);
List<Back> list = backMapper.selectAll(back);
return PageInfo.of(list);
}
}

@ -0,0 +1,73 @@
package com.example.service;
import com.example.entity.Customer;
import com.example.mapper.CustomerMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import java.util.List;
/**
*
**/
@Service
public class CustomerService {
@Resource
private CustomerMapper customerMapper;
/**
*
*/
public void add(Customer customer) {
customerMapper.insert(customer);
}
/**
*
*/
public void deleteById(Integer id) {
customerMapper.deleteById(id);
}
/**
*
*/
public void deleteBatch(List<Integer> ids) {
for (Integer id : ids) {
customerMapper.deleteById(id);
}
}
/**
*
*/
public void updateById(Customer customer) {
customerMapper.updateById(customer);
}
/**
* ID
*/
public Customer selectById(Integer id) {
return customerMapper.selectById(id);
}
/**
*
*/
public List<Customer> selectAll(Customer customer) {
return customerMapper.selectAll(customer);
}
/**
*
*/
public PageInfo<Customer> selectPage(Customer customer, Integer pageNum, Integer pageSize) {
PageHelper.startPage(pageNum, pageSize);
List<Customer> list = customerMapper.selectAll(customer);
return PageInfo.of(list);
}
}

@ -0,0 +1,94 @@
package com.example.service;
import com.example.entity.Department;
import com.example.mapper.DepartmentMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
@Service
public class DepartmentService {
@Resource
private DepartmentMapper departmentMapper;
/**
*
*/
public void add(Department department) {
departmentMapper.insert(department);
}
/**
*
*/
public void deleteById(Integer id) {
departmentMapper.deleteById(id);
}
/**
*
*/
public void deleteBatch(List<Integer> ids) {
for (Integer id : ids) {
departmentMapper.deleteById(id);
}
}
/**
*
*/
public void updateById(Department department) {
departmentMapper.updateById(department);
}
/**
* ID
*/
public Department selectById(Integer id) {
return departmentMapper.selectById(id);
}
/**
*
*/
public List<Department> selectAll(Department department) {
return departmentMapper.selectAll(department);
}
/**
*
*/
public PageInfo<Department> selectPage(Department department, Integer pageNum, Integer pageSize) {
PageHelper.startPage(pageNum, pageSize);
List<Department> list = departmentMapper.selectAll(department);
return PageInfo.of(list);
}
/**
*
*/
public List<Department> selectTree() {
Department params = new Department();
params.setLevel(1); // 先查询出一级节点
List<Department> level1DepartmentList = this.selectAll(params);
for (Department level1 : level1DepartmentList) {
Integer level1Id = level1.getId();
Department params1 = new Department();
params1.setPid(level1Id); // 再查询2级节点
List<Department> leve2DepartmentList = this.selectAll(params1);
level1.setChildren(leve2DepartmentList); // 设置一级节点的子节点
for (Department level2 : leve2DepartmentList) {
Integer level2Id = level2.getId();
Department params2 = new Department();
params2.setPid(level2Id); // 查询三级节点
List<Department> leve3DepartmentList = this.selectAll(params2);
level2.setChildren(leve3DepartmentList); // 设置儿级节点的子节点
}
}
return level1DepartmentList;
}
}

@ -0,0 +1,73 @@
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 javax.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 deleteBatch(List<Integer> ids) {
for (Integer id : ids) {
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,104 @@
package com.example.service;
import cn.hutool.core.date.DateUtil;
import com.example.entity.Logs;
import com.example.mapper.LogsMapper;
import com.example.utils.IpUtils;
import com.example.utils.TokenUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Service;
import java.util.List;
/**
*
**/
@Service
public class LogsService implements InitializingBean {
@Resource
private LogsMapper logsMapper;
@Resource
HttpServletRequest request;
private static LogsMapper staticLogsMapper;
private static HttpServletRequest staticHttpServletRequest;
/**
*
*/
public static void recordLog(String operation, String type, String username) {
Logs logs = new Logs();
logs.setOperation(operation);
logs.setType(type);
logs.setTime(DateUtil.now());
logs.setIp(IpUtils.getIpAddr(staticHttpServletRequest));
logs.setUsername(username);
staticLogsMapper.insert(logs);
}
/**
*
*/
public void add(Logs logs) {
logsMapper.insert(logs);
}
/**
*
*/
public void deleteById(Integer id) {
logsMapper.deleteById(id);
}
/**
*
*/
public void deleteBatch(List<Integer> ids) {
for (Integer id : ids) {
logsMapper.deleteById(id);
}
}
/**
*
*/
public void updateById(Logs logs) {
logsMapper.updateById(logs);
}
/**
* ID
*/
public Logs selectById(Integer id) {
return logsMapper.selectById(id);
}
/**
*
*/
public List<Logs> selectAll(Logs logs) {
return logsMapper.selectAll(logs);
}
/**
*
*/
public PageInfo<Logs> selectPage(Logs logs, Integer pageNum, Integer pageSize) {
PageHelper.startPage(pageNum, pageSize);
List<Logs> list = logsMapper.selectAll(logs);
return PageInfo.of(list);
}
@Override
public void afterPropertiesSet() throws Exception {
staticLogsMapper = this.logsMapper;
staticHttpServletRequest = this.request;
}
}

@ -0,0 +1,79 @@
package com.example.service;
import cn.hutool.core.date.DateUtil;
import com.example.entity.Account;
import com.example.entity.Notice;
import com.example.mapper.NoticeMapper;
import com.example.utils.TokenUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import javax.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.today());
Account currentUser = TokenUtils.getCurrentUser();
notice.setUser(currentUser.getUsername());
noticeMapper.insert(notice);
}
/**
*
*/
public void deleteById(Integer id) {
noticeMapper.deleteById(id);
}
/**
*
*/
public void deleteBatch(List<Integer> ids) {
for (Integer id : ids) {
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,84 @@
package com.example.service;
import com.example.entity.Goods;
import com.example.entity.SaleBack;
import com.example.mapper.SaleBackMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.List;
/**
*
**/
@Service
public class SaleBackService {
@Resource
private SaleBackMapper saleBackMapper;
@Resource
private GoodsService goodsService;
/**
*
*/
@Transactional
public void add(SaleBack saleBack) {
Goods goods = goodsService.selectById(saleBack.getGoodsId());
goods.setNum(goods.getNum() + saleBack.getNum()); // 销售退货 增加库存
goodsService.updateById(goods);
saleBackMapper.insert(saleBack);
}
/**
*
*/
public void deleteById(Integer id) {
saleBackMapper.deleteById(id);
}
/**
*
*/
public void deleteBatch(List<Integer> ids) {
for (Integer id : ids) {
saleBackMapper.deleteById(id);
}
}
/**
*
*/
public void updateById(SaleBack saleBack) {
saleBackMapper.updateById(saleBack);
}
/**
* ID
*/
public SaleBack selectById(Integer id) {
return saleBackMapper.selectById(id);
}
/**
*
*/
public List<SaleBack> selectAll(SaleBack saleBack) {
return saleBackMapper.selectAll(saleBack);
}
/**
*
*/
public PageInfo<SaleBack> selectPage(SaleBack saleBack, Integer pageNum, Integer pageSize) {
PageHelper.startPage(pageNum, pageSize);
List<SaleBack> list = saleBackMapper.selectAll(saleBack);
return PageInfo.of(list);
}
}

@ -0,0 +1,97 @@
package com.example.service;
import com.example.common.enums.ResultCodeEnum;
import com.example.entity.Account;
import com.example.entity.Goods;
import com.example.entity.Sale;
import com.example.exception.CustomException;
import com.example.mapper.SaleMapper;
import com.example.utils.TokenUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.List;
/**
*
**/
@Service
public class SaleService {
@Resource
private SaleMapper saleMapper;
@Resource
private GoodsService goodsService;
/**
*
*/
@Transactional
public void add(Sale sale) {
Account currentUser = TokenUtils.getCurrentUser();
sale.setUser(currentUser.getName());
sale.setTotal(sale.getPrice() * sale.getNum());
saleMapper.insert(sale);
// 商品减库存
Goods goods = goodsService.selectById(sale.getGoodsId());
int num = goods.getNum() - sale.getNum();
if (num < 0) {
throw new CustomException(ResultCodeEnum.GOODS_NUM_LIMIT);
}
goods.setNum(num);
goodsService.updateById(goods);
}
/**
*
*/
public void deleteById(Integer id) {
saleMapper.deleteById(id);
}
/**
*
*/
public void deleteBatch(List<Integer> ids) {
for (Integer id : ids) {
saleMapper.deleteById(id);
}
}
/**
*
*/
public void updateById(Sale sale) {
sale.setTotal(sale.getPrice() * sale.getNum());
saleMapper.updateById(sale);
}
/**
* ID
*/
public Sale selectById(Integer id) {
return saleMapper.selectById(id);
}
/**
*
*/
public List<Sale> selectAll(Sale sale) {
return saleMapper.selectAll(sale);
}
/**
*
*/
public PageInfo<Sale> selectPage(Sale sale, Integer pageNum, Integer pageSize) {
PageHelper.startPage(pageNum, pageSize);
List<Sale> list = saleMapper.selectAll(sale);
return PageInfo.of(list);
}
}

@ -0,0 +1,129 @@
package com.example.service;
import cn.hutool.core.util.ObjectUtil;
import com.example.common.Constants;
import com.example.common.enums.ResultCodeEnum;
import com.example.common.enums.RoleEnum;
import com.example.entity.Account;
import com.example.entity.Admin;
import com.example.entity.Staff;
import com.example.exception.CustomException;
import com.example.mapper.StaffMapper;
import com.example.utils.TokenUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
@Service
public class StaffService {
@Resource
private StaffMapper staffMapper;
/**
*
*/
public void add(Staff staff) {
Staff dbStaff = staffMapper.selectByUsername(staff.getUsername());
if (ObjectUtil.isNotNull(dbStaff)) {
throw new CustomException(ResultCodeEnum.USER_EXIST_ERROR);
}
if (ObjectUtil.isEmpty(staff.getPassword())) {
staff.setPassword(Constants.USER_DEFAULT_PASSWORD);
}
if (ObjectUtil.isEmpty(staff.getName())) {
staff.setName(staff.getUsername());
}
staff.setRole(RoleEnum.STAFF.name());
staffMapper.insert(staff);
}
/**
*
*/
public void deleteById(Integer id) {
staffMapper.deleteById(id);
}
/**
*
*/
public void deleteBatch(List<Integer> ids) {
for (Integer id : ids) {
staffMapper.deleteById(id);
}
}
/**
*
*/
public void updateById(Staff staff) {
staffMapper.updateById(staff);
}
/**
* ID
*/
public Staff selectById(Integer id) {
return staffMapper.selectById(id);
}
/**
*
*/
public List<Staff> selectAll(Staff staff) {
return staffMapper.selectAll(staff);
}
/**
*
*/
public PageInfo<Staff> selectPage(Staff staff, Integer pageNum, Integer pageSize) {
PageHelper.startPage(pageNum, pageSize);
List<Staff> list = staffMapper.selectAll(staff);
return PageInfo.of(list);
}
public Account login(Account account) {
Account dbStaff = staffMapper.selectByUsername(account.getUsername());
if (ObjectUtil.isNull(dbStaff)) {
throw new CustomException(ResultCodeEnum.USER_NOT_EXIST_ERROR);
}
if (dbStaff.getStatus()) { // 如果是禁用的员工,不允许登录
throw new CustomException(ResultCodeEnum.NO_AUTH);
}
if (!account.getPassword().equals(dbStaff.getPassword())) {
throw new CustomException(ResultCodeEnum.USER_ACCOUNT_ERROR);
}
// 生成token
String tokenData = dbStaff.getId() + "-" + RoleEnum.STAFF.name();
String token = TokenUtils.createToken(tokenData, dbStaff.getPassword());
dbStaff.setToken(token);
return dbStaff;
}
/**
*
*/
public void register(Account account) {
Staff staff = new Staff();
BeanUtils.copyProperties(account, staff);
this.add(staff);
}
public void updatePassword(Account account) {
Staff staff = staffMapper.selectByUsername(account.getUsername());
if (ObjectUtil.isNull(staff)) {
throw new CustomException(ResultCodeEnum.USER_NOT_EXIST_ERROR);
}
if (!account.getPassword().equals(staff.getPassword())) {
throw new CustomException(ResultCodeEnum.PARAM_PASSWORD_ERROR);
}
staff.setPassword(account.getNewPassword());
staffMapper.updateById(staff);
}
}

@ -0,0 +1,92 @@
package com.example.service;
import com.example.entity.Account;
import com.example.entity.Goods;
import com.example.entity.Stock;
import com.example.mapper.StockMapper;
import com.example.utils.TokenUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
/**
*
**/
@Service
public class StockService {
@Resource
private StockMapper stockMapper;
@Resource
private GoodsService goodsService;
/**
*
*/
@Transactional
public void add(Stock stock) {
Account currentUser = TokenUtils.getCurrentUser();
stock.setUser(currentUser.getName());
stock.setTotal(stock.getPrice() * stock.getNum());
// 查询进货的商品信息
Goods goods = goodsService.selectById(stock.getGoodsId());
goods.setNum(goods.getNum() + stock.getNum());
goodsService.updateById(goods);
stockMapper.insert(stock);
}
/**
*
*/
public void deleteById(Integer id) {
stockMapper.deleteById(id);
}
/**
*
*/
public void deleteBatch(List<Integer> ids) {
for (Integer id : ids) {
stockMapper.deleteById(id);
}
}
/**
*
*/
public void updateById(Stock stock) {
stock.setTotal(stock.getPrice() * stock.getNum());
stockMapper.updateById(stock);
}
/**
* ID
*/
public Stock selectById(Integer id) {
return stockMapper.selectById(id);
}
/**
*
*/
public List<Stock> selectAll(Stock stock) {
return stockMapper.selectAll(stock);
}
/**
*
*/
public PageInfo<Stock> selectPage(Stock stock, Integer pageNum, Integer pageSize) {
PageHelper.startPage(pageNum, pageSize);
List<Stock> list = stockMapper.selectAll(stock);
return PageInfo.of(list);
}
}

@ -0,0 +1,73 @@
package com.example.service;
import com.example.entity.Supplier;
import com.example.mapper.SupplierMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import java.util.List;
/**
*
**/
@Service
public class SupplierService {
@Resource
private SupplierMapper supplierMapper;
/**
*
*/
public void add(Supplier supplier) {
supplierMapper.insert(supplier);
}
/**
*
*/
public void deleteById(Integer id) {
supplierMapper.deleteById(id);
}
/**
*
*/
public void deleteBatch(List<Integer> ids) {
for (Integer id : ids) {
supplierMapper.deleteById(id);
}
}
/**
*
*/
public void updateById(Supplier supplier) {
supplierMapper.updateById(supplier);
}
/**
* ID
*/
public Supplier selectById(Integer id) {
return supplierMapper.selectById(id);
}
/**
*
*/
public List<Supplier> selectAll(Supplier supplier) {
return supplierMapper.selectAll(supplier);
}
/**
*
*/
public PageInfo<Supplier> selectPage(Supplier supplier, Integer pageNum, Integer pageSize) {
PageHelper.startPage(pageNum, pageSize);
List<Supplier> list = supplierMapper.selectAll(supplier);
return PageInfo.of(list);
}
}

@ -0,0 +1,34 @@
package com.example.service;
import com.example.common.Result;
import com.example.mapper.WarnMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
@Service
public class WarnService {
@Autowired
private WarnMapper warnMapper;
public Result warning() {
List<Map<String, Object>> much = warnMapper.much();
List<Map<String, Object>> little = warnMapper.little();
StringBuilder sb = new StringBuilder();
sb.append("下列货物滞销:\n");
int i = 1;
for (Map<String, Object> map : much) {
sb.append(i + "、" + map.get("name") + "(" + map.get("num") + ")\n");
i++;
}
sb.append("\n");
sb.append("下列货物缺货:\n");
int j = 1;
for (Map<String, Object> map : little) {
sb.append(j + "、" + map.get("name") + "(" + map.get("num") + ")\n");
j++;
}
return Result.success(sb.toString());
}
}

@ -0,0 +1,40 @@
package com.example.utils;
public class CodeCache {
private String key; // 前端传来的 uuid唯一标识
private String code; // 验证码
private long timestamp; // 时间戳
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public long getTimestamp() {
return timestamp;
}
public void setTimestamp(long timestamp) {
this.timestamp = timestamp;
}
@Override
public String toString() {
return "CodeCache{" +
"key='" + key + '\'' +
", code='" + code + '\'' +
", timestamp=" + timestamp +
'}';
}
}

@ -0,0 +1,33 @@
package com.example.utils;
import javax.servlet.http.HttpServletRequest;
public class IpUtils {
/**
* IP
* @param request
* @return
*/
public static String getIpAddr(HttpServletRequest request) {
String ip = request.getHeader("x-forwarded-for");
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("Proxy-Client-IP");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("X-Forwarded-For");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("WL-Proxy-Client-IP");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("X-Real-IP");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getRemoteAddr();
}
return "0:0:0:0:0:0:0:1".equals(ip) ? "127.0.0.1" : ip;
}
}

@ -0,0 +1,78 @@
package com.example.utils;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import com.example.common.Constants;
import com.example.common.enums.RoleEnum;
import com.example.entity.Account;
import com.example.service.AdminService;
import com.example.service.StaffService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
/**
* Token
*/
@Component
public class TokenUtils {
private static final Logger log = LoggerFactory.getLogger(TokenUtils.class);
private static AdminService staticAdminService;
private static StaffService staticStaffService;
@Resource
AdminService adminService;
@Resource
StaffService staffService;
@PostConstruct
public void setUserService() {
staticAdminService = adminService;
staticStaffService = staffService;
}
/**
* token
*/
public static String createToken(String data, String sign) {
return JWT.create().withAudience(data) // 将 userId-role 保存到 token 里面,作为载荷
.withExpiresAt(DateUtil.offsetHour(new Date(), 2)) // 2小时后token过期
.sign(Algorithm.HMAC256(sign)); // 以 password 作为 token 的密钥
}
/**
*
*/
public static Account getCurrentUser() {
try {
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
String token = request.getHeader(Constants.TOKEN);
if (ObjectUtil.isNotEmpty(token)) {
String userRole = JWT.decode(token).getAudience().get(0);
String userId = userRole.split("-")[0]; // 获取用户id
String role = userRole.split("-")[1]; // 获取角色
if (RoleEnum.ADMIN.name().equals(role)) {
return staticAdminService.selectById(Integer.valueOf(userId));
} else if (RoleEnum.STAFF.name().equals(role)) {
return staticStaffService.selectById(Integer.valueOf(userId));
}
}
} catch (Exception e) {
log.error("获取当前用户信息出错", e);
}
return new Account(); // 返回空的账号对象
}
}

@ -0,0 +1,53 @@
package com.example.utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
@Component
public class ValidateCodeCache {
private static final Logger log = LoggerFactory.getLogger(ValidateCodeCache.class);
private static List<CodeCache> codeCache = new ArrayList<>();
/**
*
*/
public static void setCache(String key, String code) {
CodeCache cache = new CodeCache();
cache.setKey(key);
cache.setCode(code);
cache.setTimestamp(System.currentTimeMillis());
codeCache.add(cache);
log.info("当前的验证码缓存: {}", codeCache);
}
/**
*
*/
public static boolean validateCode(String key, String code) {
return codeCache.stream().anyMatch(cache -> cache.getKey().equals(key) && cache.getCode().equalsIgnoreCase(code));
}
@Scheduled(fixedRate = 60000) // 1分钟清理一次
public void task() {
log.info("=======================开始清理验证码缓存,验证码集合缓存长度: " + codeCache.size() + "=======================");
List<CodeCache> codeList = codeCache.stream().filter(cache -> {
long timestamp = cache.getTimestamp();
long duration = System.currentTimeMillis() - timestamp;
return duration > 120000; // 2分钟过期
}).collect(Collectors.toList());
codeCache.removeAll(codeList); // 清除过期的缓存
if (codeCache.size() > 1024) { // 当缓存的长度太长 到达阈值的时候 清空所有缓存
codeCache.clear();
}
log.info("=======================清理验证码缓存结束,验证码集合缓存长度: " + codeCache.size() + "=======================");
}
}

@ -0,0 +1,80 @@
package com.example.utils;
public class ValidateCodeProperties {
/**
*
*/
private Long time = 120L;
/**
* png gif
*/
private String type = "png";
/**
* px
*/
private Integer width = 130;
/**
* px
*/
private Integer height = 48;
/**
*
*/
private Integer length = 4;
/**
*
* 1.
* 2.
* 3.
*/
private Integer charType = 2;
public Long getTime() {
return time;
}
public void setTime(Long time) {
this.time = time;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public Integer getWidth() {
return width;
}
public void setWidth(Integer width) {
this.width = width;
}
public Integer getHeight() {
return height;
}
public void setHeight(Integer height) {
this.height = height;
}
public Integer getLength() {
return length;
}
public void setLength(Integer length) {
this.length = length;
}
public Integer getCharType() {
return charType;
}
public void setCharType(Integer charType) {
this.charType = charType;
}
}

@ -0,0 +1,31 @@
server:
port: 9090
# 数据库配置
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
username: root #你本地的数据库用户名
password: 123456 #你本地的数据库密码
url: jdbc:mysql://localhost:3306/psi_manager?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
type-aliases-package: com.example.entity
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
map-underscore-to-camel-case: true
# 分页
pagehelper:
helper-dialect: mysql
reasonable: true
support-methods-arguments: true
params: count=countSql
ip: localhost

@ -0,0 +1,91 @@
<?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">
<sql id="Base_Column_List">
id,username,password,name,phone,email,avatar,role
</sql>
<select id="selectAll" resultType="com.example.entity.Admin">
select
<include refid="Base_Column_List" />
from admin
<where>
<if test="id != null"> and id= #{id}</if>
<if test="username != null"> and username like concat('%', #{username}, '%')</if>
<if test="password != null"> and password= #{password}</if>
<if test="name != null"> and name= #{name}</if>
<if test="phone != null"> and phone= #{phone}</if>
<if test="email != null"> and email= #{email}</if>
<if test="avatar != null"> and avatar= #{avatar}</if>
<if test="role != null"> and role= #{role}</if>
</where>
</select>
<select id="selectById" resultType="com.example.entity.Admin">
select
<include refid="Base_Column_List" />
from admin
where id = #{id}
</select>
<delete id="deleteById">
delete from admin
where id = #{id}
</delete>
<insert id="insert" parameterType="com.example.entity.Admin" useGeneratedKeys="true">
insert into admin
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">id,</if>
<if test="username != null">username,</if>
<if test="password != null">password,</if>
<if test="name != null">name,</if>
<if test="phone != null">phone,</if>
<if test="email != null">email,</if>
<if test="avatar != null">avatar,</if>
<if test="role != null">role,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">#{id},</if>
<if test="username != null">#{username},</if>
<if test="password != null">#{password},</if>
<if test="name != null">#{name},</if>
<if test="phone != null">#{phone},</if>
<if test="email != null">#{email},</if>
<if test="avatar != null">#{avatar},</if>
<if test="role != null">#{role},</if>
</trim>
</insert>
<update id="updateById" parameterType="com.example.entity.Admin">
update admin
<set>
<if test="username != null">
username = #{username},
</if>
<if test="password != null">
password = #{password},
</if>
<if test="name != null">
name = #{name},
</if>
<if test="phone != null">
phone = #{phone},
</if>
<if test="email != null">
email = #{email},
</if>
<if test="avatar != null">
avatar = #{avatar},
</if>
<if test="role != null">
role = #{role},
</if>
</set>
where id = #{id}
</update>
</mapper>

@ -0,0 +1,106 @@
<?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.BackMapper">
<sql id="Base_Column_List">
id,supplier_id,goods_id,pay_type,time,user,num,unit,price,total,comment
</sql>
<select id="selectAll" resultType="com.example.entity.Back">
select
back.*, supplier.name as supplierName, goods.name as goodsName
from back
left join supplier
on back.supplier_id = supplier.id
left join goods
on back.goods_id = goods.id
<where>
<if test="id != null"> and back.id = #{id}</if>
<if test="supplierName != null"> and supplier.name like concat('%', #{supplierName}, '%')</if>
<if test="goodsName != null"> and goods.name like concat('%', #{goodsName}, '%')</if>
</where>
order by id desc
</select>
<select id="selectById" resultType="com.example.entity.Back">
select
<include refid="Base_Column_List" />
from back
where id = #{id}
</select>
<delete id="deleteById">
delete from back
where id = #{id}
</delete>
<insert id="insert" parameterType="com.example.entity.Back" useGeneratedKeys="true">
insert into back
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">id,</if>
<if test="supplierId != null">supplier_id,</if>
<if test="goodsId != null">goods_id,</if>
<if test="payType != null">pay_type,</if>
<if test="time != null">time,</if>
<if test="user != null">user,</if>
<if test="num != null">num,</if>
<if test="unit != null">unit,</if>
<if test="price != null">price,</if>
<if test="total != null">total,</if>
<if test="comment != null">comment,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">#{id},</if>
<if test="supplierId != null">#{supplierId},</if>
<if test="goodsId != null">#{goodsId},</if>
<if test="payType != null">#{payType},</if>
<if test="time != null">#{time},</if>
<if test="user != null">#{user},</if>
<if test="num != null">#{num},</if>
<if test="unit != null">#{unit},</if>
<if test="price != null">#{price},</if>
<if test="total != null">#{total},</if>
<if test="comment != null">#{comment},</if>
</trim>
</insert>
<update id="updateById" parameterType="com.example.entity.Back">
update back
<set>
<if test="supplierId != null">
supplier_id = #{supplierId},
</if>
<if test="goodsId != null">
goods_id = #{goodsId},
</if>
<if test="payType != null">
pay_type = #{payType},
</if>
<if test="time != null">
time = #{time},
</if>
<if test="user != null">
user = #{user},
</if>
<if test="num != null">
num = #{num},
</if>
<if test="unit != null">
unit = #{unit},
</if>
<if test="price != null">
price = #{price},
</if>
<if test="total != null">
total = #{total},
</if>
<if test="comment != null">
comment = #{comment},
</if>
</set>
where id = #{id}
</update>
</mapper>

@ -0,0 +1,110 @@
<?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.CustomerMapper">
<sql id="Base_Column_List">
id,name,address,tel,email,zip_code,user,phone,bank,bank_card,status
</sql>
<select id="selectAll" resultType="com.example.entity.Customer">
select
<include refid="Base_Column_List" />
from customer
<where>
<if test="id != null"> and id = #{id}</if>
<if test="name != null"> and name like concat('%', #{name}, '%')</if>
<if test="address != null"> and address like concat('%', #{address}, '%')</if>
<if test="tel != null"> and tel like concat('%', #{tel}, '%')</if>
<if test="email != null"> and email like concat('%', #{email}, '%')</if>
<if test="zipCode != null"> and zip_code like concat('%', #{zipCode}, '%')</if>
<if test="user != null"> and user like concat('%', #{user}, '%')</if>
<if test="phone != null"> and phone like concat('%', #{phone}, '%')</if>
<if test="bank != null"> and bank like concat('%', #{bank}, '%')</if>
<if test="bankCard != null"> and bank_card like concat('%', #{bankCard}, '%')</if>
<if test="status != null"> and status like concat('%', #{status}, '%')</if>
</where>
order by id desc
</select>
<select id="selectById" resultType="com.example.entity.Customer">
select
<include refid="Base_Column_List" />
from customer
where id = #{id}
</select>
<delete id="deleteById">
delete from customer
where id = #{id}
</delete>
<insert id="insert" parameterType="com.example.entity.Customer" useGeneratedKeys="true">
insert into customer
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">id,</if>
<if test="name != null">name,</if>
<if test="address != null">address,</if>
<if test="tel != null">tel,</if>
<if test="email != null">email,</if>
<if test="zipCode != null">zip_code,</if>
<if test="user != null">user,</if>
<if test="phone != null">phone,</if>
<if test="bank != null">bank,</if>
<if test="bankCard != null">bank_card,</if>
<if test="status != null">status,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">#{id},</if>
<if test="name != null">#{name},</if>
<if test="address != null">#{address},</if>
<if test="tel != null">#{tel},</if>
<if test="email != null">#{email},</if>
<if test="zipCode != null">#{zipCode},</if>
<if test="user != null">#{user},</if>
<if test="phone != null">#{phone},</if>
<if test="bank != null">#{bank},</if>
<if test="bankCard != null">#{bankCard},</if>
<if test="status != null">#{status},</if>
</trim>
</insert>
<update id="updateById" parameterType="com.example.entity.Customer">
update customer
<set>
<if test="name != null">
name = #{name},
</if>
<if test="address != null">
address = #{address},
</if>
<if test="tel != null">
tel = #{tel},
</if>
<if test="email != null">
email = #{email},
</if>
<if test="zipCode != null">
zip_code = #{zipCode},
</if>
<if test="user != null">
user = #{user},
</if>
<if test="phone != null">
phone = #{phone},
</if>
<if test="bank != null">
bank = #{bank},
</if>
<if test="bankCard != null">
bank_card = #{bankCard},
</if>
<if test="status != null">
status = #{status},
</if>
</set>
where id = #{id}
</update>
</mapper>

@ -0,0 +1,72 @@
<?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.DepartmentMapper">
<sql id="Base_Column_List">
id,name,address,pid,level
</sql>
<select id="selectAll" resultType="com.example.entity.Department">
select
<include refid="Base_Column_List" />
from department
<where>
<if test="name != null"> and name like concat('%', #{name}, '%')</if>
<if test="level != null"> and level = #{ level}</if>
<if test="pid != null"> and pid = #{ pid }</if>
</where>
order by id desc
</select>
<select id="selectById" resultType="com.example.entity.Department">
select
<include refid="Base_Column_List" />
from department
where id = #{id}
</select>
<delete id="deleteById">
delete from department
where id = #{id}
</delete>
<insert id="insert" parameterType="com.example.entity.Department" useGeneratedKeys="true">
insert into department
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">id,</if>
<if test="name != null">name,</if>
<if test="address != null">address,</if>
<if test="pid != null">pid,</if>
<if test="level != null">level,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">#{id},</if>
<if test="name != null">#{name},</if>
<if test="address != null">#{address},</if>
<if test="pid != null">#{pid},</if>
<if test="level != null">#{level},</if>
</trim>
</insert>
<update id="updateById" parameterType="com.example.entity.Department">
update department
<set>
<if test="name != null">
name = #{name},
</if>
<if test="address != null">
address = #{address},
</if>
<if test="pid != null">
pid = #{pid},
</if>
<if test="level != null">
level = #{level},
</if>
</set>
where id = #{id}
</update>
</mapper>

@ -0,0 +1,117 @@
<?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">
<sql id="Base_Column_List">
id,name,supplier_id,producer,descr,price,num,img,unit,pack,product_no,approve_no,status
</sql>
<select id="selectAll" resultType="com.example.entity.Goods">
select
goods.*, supplier.name as supplierName
from goods
left join supplier
on goods.supplier_id = supplier.id
<where>
<if test="id != null"> and goods.id = #{id}</if>
<if test="supplierId != null"> and goods.supplier_id = #{supplierId}</if>
<if test="name != null"> and goods.name like concat('%', #{name}, '%')</if>
<if test="supplierName != null"> and supplier.name like concat('%', #{supplierName}, '%')</if>
<if test="productNo != null"> and goods.product_no like concat('%', #{productNo}, '%')</if>
<if test="approveNo != null"> and goods.approve_no like concat('%', #{approveNo}, '%')</if>
</where>
order by id desc
</select>
<select id="selectById" resultType="com.example.entity.Goods">
select
<include refid="Base_Column_List" />
from goods
where id = #{id}
</select>
<delete id="deleteById">
delete from goods
where id = #{id}
</delete>
<insert id="insert" parameterType="com.example.entity.Goods" useGeneratedKeys="true">
insert into goods
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">id,</if>
<if test="name != null">name,</if>
<if test="supplierId != null">supplier_id,</if>
<if test="producer != null">producer,</if>
<if test="descr != null">descr,</if>
<if test="price != null">price,</if>
<if test="num != null">num,</if>
<if test="img != null">img,</if>
<if test="unit != null">unit,</if>
<if test="pack != null">pack,</if>
<if test="productNo != null">product_no,</if>
<if test="approveNo != null">approve_no,</if>
<if test="status != null">status,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">#{id},</if>
<if test="name != null">#{name},</if>
<if test="supplierId != null">#{supplierId},</if>
<if test="producer != null">#{producer},</if>
<if test="descr != null">#{descr},</if>
<if test="price != null">#{price},</if>
<if test="num != null">#{num},</if>
<if test="img != null">#{img},</if>
<if test="unit != null">#{unit},</if>
<if test="pack != null">#{pack},</if>
<if test="productNo != null">#{productNo},</if>
<if test="approveNo != null">#{approveNo},</if>
<if test="status != null">#{status},</if>
</trim>
</insert>
<update id="updateById" parameterType="com.example.entity.Goods">
update goods
<set>
<if test="name != null">
name = #{name},
</if>
<if test="supplierId != null">
supplier_id = #{supplierId},
</if>
<if test="producer != null">
producer = #{producer},
</if>
<if test="descr != null">
descr = #{descr},
</if>
<if test="price != null">
price = #{price},
</if>
<if test="num != null">
num = #{num},
</if>
<if test="img != null">
img = #{img},
</if>
<if test="unit != null">
unit = #{unit},
</if>
<if test="pack != null">
pack = #{pack},
</if>
<if test="productNo != null">
product_no = #{productNo},
</if>
<if test="approveNo != null">
approve_no = #{approveNo},
</if>
<if test="status != null">
status = #{status},
</if>
</set>
where id = #{id}
</update>
</mapper>

@ -0,0 +1,76 @@
<?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.LogsMapper">
<sql id="Base_Column_List">
id,operation,username,type,ip,time
</sql>
<select id="selectAll" resultType="com.example.entity.Logs">
select
<include refid="Base_Column_List" />
from logs
<where>
<if test="id != null"> and logs.id = #{id}</if>
<if test="operation != null"> and logs.operation like concat('%', #{operation}, '%')</if>
</where>
order by id desc
</select>
<select id="selectById" resultType="com.example.entity.Logs">
select
<include refid="Base_Column_List" />
from logs
where id = #{id}
</select>
<delete id="deleteById">
delete from logs
where id = #{id}
</delete>
<insert id="insert" parameterType="com.example.entity.Logs" useGeneratedKeys="true">
insert into logs
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">id,</if>
<if test="operation != null">operation,</if>
<if test="username != null">username,</if>
<if test="type != null">type,</if>
<if test="ip != null">ip,</if>
<if test="time != null">time,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">#{id},</if>
<if test="operation != null">#{operation},</if>
<if test="username != null">#{username},</if>
<if test="type != null">#{type},</if>
<if test="ip != null">#{ip},</if>
<if test="time != null">#{time},</if>
</trim>
</insert>
<update id="updateById" parameterType="com.example.entity.Logs">
update logs
<set>
<if test="operation != null">
operation = #{operation},
</if>
<if test="username != null">
username = #{username},
</if>
<if test="type != null">
type = #{type},
</if>
<if test="ip != null">
ip = #{ip},
</if>
<if test="time != null">
time = #{time},
</if>
</set>
where id = #{id}
</update>
</mapper>

@ -0,0 +1,74 @@
<?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">
<sql id="Base_Column_List">
id,title,content,time,user
</sql>
<select id="selectAll" resultType="com.example.entity.Notice">
select
<include refid="Base_Column_List" />
from notice
<where>
<if test="id != null"> and id= #{id}</if>
<if test="title != null"> and title like concat('%', #{title}, '%')</if>
<if test="content != null"> and content= #{content}</if>
<if test="time != null"> and time= #{time}</if>
<if test="user != null"> and user= #{user}</if>
</where>
order by id desc
</select>
<select id="selectById" resultType="com.example.entity.Notice">
select
<include refid="Base_Column_List" />
from notice
where id = #{id}
</select>
<delete id="deleteById">
delete from notice
where id = #{id}
</delete>
<insert id="insert" parameterType="com.example.entity.Notice" useGeneratedKeys="true">
insert into notice
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">id,</if>
<if test="title != null">title,</if>
<if test="content != null">content,</if>
<if test="time != null">time,</if>
<if test="user != null">user,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">#{id},</if>
<if test="title != null">#{title},</if>
<if test="content != null">#{content},</if>
<if test="time != null">#{time},</if>
<if test="user != null">#{user},</if>
</trim>
</insert>
<update id="updateById" parameterType="com.example.entity.Department">
update notice
<set>
<if test="title != null">
title = #{title},
</if>
<if test="content != null">
content = #{content},
</if>
<if test="time != null">
time = #{time},
</if>
<if test="user != null">
user = #{user},
</if>
</set>
where id = #{id}
</update>
</mapper>

@ -0,0 +1,106 @@
<?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.SaleBackMapper">
<sql id="Base_Column_List">
id,customer_id,goods_id,pay_type,time,user,price,num,unit,total,comment
</sql>
<select id="selectAll" resultType="com.example.entity.SaleBack">
select
sale_back.*, customer.name as customerName, goods.name as goodsName
from sale_back
left join customer
on sale_back.customer_id = customer.id
left join goods
on sale_back.goods_id = goods.id
<where>
<if test="id != null"> and sale_back.id = #{id}</if>
<if test="customerName != null"> and customer.name like concat('%', #{customerName}, '%')</if>
<if test="goodsName != null"> and goods.name like concat('%', #{goodsName}, '%')</if>
</where>
order by id desc
</select>
<select id="selectById" resultType="com.example.entity.SaleBack">
select
<include refid="Base_Column_List" />
from sale_back
where id = #{id}
</select>
<delete id="deleteById">
delete from sale_back
where id = #{id}
</delete>
<insert id="insert" parameterType="com.example.entity.SaleBack" useGeneratedKeys="true">
insert into sale_back
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">id,</if>
<if test="customerId != null">customer_id,</if>
<if test="goodsId != null">goods_id,</if>
<if test="payType != null">pay_type,</if>
<if test="time != null">time,</if>
<if test="user != null">user,</if>
<if test="price != null">price,</if>
<if test="num != null">num,</if>
<if test="unit != null">unit,</if>
<if test="total != null">total,</if>
<if test="comment != null">comment,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">#{id},</if>
<if test="customerId != null">#{customerId},</if>
<if test="goodsId != null">#{goodsId},</if>
<if test="payType != null">#{payType},</if>
<if test="time != null">#{time},</if>
<if test="user != null">#{user},</if>
<if test="price != null">#{price},</if>
<if test="num != null">#{num},</if>
<if test="unit != null">#{unit},</if>
<if test="total != null">#{total},</if>
<if test="comment != null">#{comment},</if>
</trim>
</insert>
<update id="updateById" parameterType="com.example.entity.SaleBack">
update sale_back
<set>
<if test="customerId != null">
customer_id = #{customerId},
</if>
<if test="goodsId != null">
goods_id = #{goodsId},
</if>
<if test="payType != null">
pay_type = #{payType},
</if>
<if test="time != null">
time = #{time},
</if>
<if test="user != null">
user = #{user},
</if>
<if test="price != null">
price = #{price},
</if>
<if test="num != null">
num = #{num},
</if>
<if test="unit != null">
unit = #{unit},
</if>
<if test="total != null">
total = #{total},
</if>
<if test="comment != null">
comment = #{comment},
</if>
</set>
where id = #{id}
</update>
</mapper>

@ -0,0 +1,106 @@
<?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.SaleMapper">
<sql id="Base_Column_List">
id,customer_id,goods_id,pay_type,time,user,price,num,unit,total,comment
</sql>
<select id="selectAll" resultType="com.example.entity.Sale">
select
sale.*, customer.name as customerName, goods.name as goodsName
from sale
left join customer
on sale.customer_id = customer.id
left join goods
on sale.goods_id = goods.id
<where>
<if test="id != null"> and id = #{id}</if>
<if test="customerName != null"> and customer.name like concat('%', #{customerName}, '%')</if>
<if test="goodsName != null"> and goods.name like concat('%', #{goodsName}, '%')</if>
</where>
order by id desc
</select>
<select id="selectById" resultType="com.example.entity.Sale">
select
<include refid="Base_Column_List" />
from sale
where id = #{id}
</select>
<delete id="deleteById">
delete from sale
where id = #{id}
</delete>
<insert id="insert" parameterType="com.example.entity.Sale" useGeneratedKeys="true">
insert into sale
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">id,</if>
<if test="customerId != null">customer_id,</if>
<if test="goodsId != null">goods_id,</if>
<if test="payType != null">pay_type,</if>
<if test="time != null">time,</if>
<if test="user != null">user,</if>
<if test="price != null">price,</if>
<if test="num != null">num,</if>
<if test="unit != null">unit,</if>
<if test="total != null">total,</if>
<if test="comment != null">comment,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">#{id},</if>
<if test="customerId != null">#{customerId},</if>
<if test="goodsId != null">#{goodsId},</if>
<if test="payType != null">#{payType},</if>
<if test="time != null">#{time},</if>
<if test="user != null">#{user},</if>
<if test="price != null">#{price},</if>
<if test="num != null">#{num},</if>
<if test="unit != null">#{unit},</if>
<if test="total != null">#{total},</if>
<if test="comment != null">#{comment},</if>
</trim>
</insert>
<update id="updateById" parameterType="com.example.entity.Sale">
update sale
<set>
<if test="customerId != null">
customer_id = #{customerId},
</if>
<if test="goodsId != null">
goods_id = #{goodsId},
</if>
<if test="payType != null">
pay_type = #{payType},
</if>
<if test="time != null">
time = #{time},
</if>
<if test="user != null">
user = #{user},
</if>
<if test="price != null">
price = #{price},
</if>
<if test="num != null">
num = #{num},
</if>
<if test="unit != null">
unit = #{unit},
</if>
<if test="total != null">
total = #{total},
</if>
<if test="comment != null">
comment = #{comment},
</if>
</set>
where id = #{id}
</update>
</mapper>

@ -0,0 +1,118 @@
<?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.StaffMapper">
<sql id="Base_Column_List">
id,username,password,name,phone,email,avatar,role,sex,birth,department_id,status
</sql>
<select id="selectAll" resultType="com.example.entity.Staff">
select
staff.*, department.name as departmentName
from staff
left join department
on staff.department_id = department.id
<where>
<if test="username != null"> and staff.username like concat('%', #{username}, '%')</if>
<if test="departmentName != null"> and department.name like concat('%', #{departmentName}, '%')</if>
</where>
</select>
<select id="selectById" resultType="com.example.entity.Staff">
select
staff.*, department.name as departmentName
from staff
left join department
on staff.department_id = department.id
where staff.id = #{id}
</select>
<select id="selectByUsername" resultType="com.example.entity.Staff">
select
staff.*, department.name as departmentName
from staff
left join department
on staff.department_id = department.id
where staff.username = #{username}
</select>
<delete id="deleteById">
delete from staff
where id = #{id}
</delete>
<insert id="insert" parameterType="com.example.entity.Staff" useGeneratedKeys="true">
insert into staff
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">id,</if>
<if test="username != null">username,</if>
<if test="password != null">password,</if>
<if test="name != null">name,</if>
<if test="phone != null">phone,</if>
<if test="email != null">email,</if>
<if test="avatar != null">avatar,</if>
<if test="role != null">role,</if>
<if test="sex != null">sex,</if>
<if test="birth != null">birth,</if>
<if test="departmentId != null">department_id,</if>
<if test="status != null">status,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">#{id},</if>
<if test="username != null">#{username},</if>
<if test="password != null">#{password},</if>
<if test="name != null">#{name},</if>
<if test="phone != null">#{phone},</if>
<if test="email != null">#{email},</if>
<if test="avatar != null">#{avatar},</if>
<if test="role != null">#{role},</if>
<if test="sex != null">#{sex},</if>
<if test="birth != null">#{birth},</if>
<if test="departmentId != null">#{departmentId},</if>
<if test="status != null">#{status},</if>
</trim>
</insert>
<update id="updateById" parameterType="com.example.entity.Staff">
update staff
<set>
<if test="username != null">
username = #{username},
</if>
<if test="password != null">
password = #{password},
</if>
<if test="name != null">
name = #{name},
</if>
<if test="phone != null">
phone = #{phone},
</if>
<if test="email != null">
email = #{email},
</if>
<if test="avatar != null">
avatar = #{avatar},
</if>
<if test="role != null">
role = #{role},
</if>
<if test="sex != null">
sex = #{sex},
</if>
<if test="birth != null">
birth = #{birth},
</if>
<if test="departmentId != null">
department_id = #{departmentId},
</if>
<if test="status != null">
status = #{status},
</if>
</set>
where id = #{id}
</update>
</mapper>

@ -0,0 +1,106 @@
<?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.StockMapper">
<sql id="Base_Column_List">
id,supplier_id,goods_id,pay_type,time,user,num,unit,price,total,comment
</sql>
<select id="selectAll" resultType="com.example.entity.Stock">
select
stock.*, supplier.name as supplierName, goods.name as goodsName
from stock
left join supplier
on stock.supplier_id = supplier.id
left join goods
on stock.goods_id = goods.id
<where>
<if test="id != null"> and stock.id = #{id}</if>
<if test="supplierName != null"> and supplier.name like concat('%', #{supplierName}, '%')</if>
<if test="goodsName != null"> and goods.name like concat('%', #{goodsName}, '%')</if>
</where>
order by id desc
</select>
<select id="selectById" resultType="com.example.entity.Stock">
select
<include refid="Base_Column_List" />
from stock
where id = #{id}
</select>
<delete id="deleteById">
delete from stock
where id = #{id}
</delete>
<insert id="insert" parameterType="com.example.entity.Stock" useGeneratedKeys="true">
insert into stock
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">id,</if>
<if test="supplierId != null">supplier_id,</if>
<if test="goodsId != null">goods_id,</if>
<if test="payType != null">pay_type,</if>
<if test="time != null">time,</if>
<if test="user != null">user,</if>
<if test="num != null">num,</if>
<if test="unit != null">unit,</if>
<if test="price != null">price,</if>
<if test="total != null">total,</if>
<if test="comment != null">comment,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">#{id},</if>
<if test="supplierId != null">#{supplierId},</if>
<if test="goodsId != null">#{goodsId},</if>
<if test="payType != null">#{payType},</if>
<if test="time != null">#{time},</if>
<if test="user != null">#{user},</if>
<if test="num != null">#{num},</if>
<if test="unit != null">#{unit},</if>
<if test="price != null">#{price},</if>
<if test="total != null">#{total},</if>
<if test="comment != null">#{comment},</if>
</trim>
</insert>
<update id="updateById" parameterType="com.example.entity.Stock">
update stock
<set>
<if test="supplierId != null">
supplier_id = #{supplierId},
</if>
<if test="goodsId != null">
goods_id = #{goodsId},
</if>
<if test="payType != null">
pay_type = #{payType},
</if>
<if test="time != null">
time = #{time},
</if>
<if test="user != null">
user = #{user},
</if>
<if test="num != null">
num = #{num},
</if>
<if test="unit != null">
unit = #{unit},
</if>
<if test="price != null">
price = #{price},
</if>
<if test="total != null">
total = #{total},
</if>
<if test="comment != null">
comment = #{comment},
</if>
</set>
where id = #{id}
</update>
</mapper>

@ -0,0 +1,110 @@
<?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.SupplierMapper">
<sql id="Base_Column_List">
id,name,address,tel,email,zip_code,user,phone,bank,bank_card,status
</sql>
<select id="selectAll" resultType="com.example.entity.Supplier">
select
<include refid="Base_Column_List" />
from supplier
<where>
<if test="id != null"> and id = #{id}</if>
<if test="name != null"> and name like concat('%', #{name}, '%')</if>
<if test="address != null"> and address like concat('%', #{address}, '%')</if>
<if test="tel != null"> and tel like concat('%', #{tel}, '%')</if>
<if test="email != null"> and email like concat('%', #{email}, '%')</if>
<if test="zipCode != null"> and zip_code like concat('%', #{zipCode}, '%')</if>
<if test="user != null"> and user like concat('%', #{user}, '%')</if>
<if test="phone != null"> and phone like concat('%', #{phone}, '%')</if>
<if test="bank != null"> and bank like concat('%', #{bank}, '%')</if>
<if test="bankCard != null"> and bank_card like concat('%', #{bankCard}, '%')</if>
<if test="status != null"> and status like concat('%', #{status}, '%')</if>
</where>
order by id desc
</select>
<select id="selectById" resultType="com.example.entity.Supplier">
select
<include refid="Base_Column_List" />
from supplier
where id = #{id}
</select>
<delete id="deleteById">
delete from supplier
where id = #{id}
</delete>
<insert id="insert" parameterType="com.example.entity.Supplier" useGeneratedKeys="true">
insert into supplier
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">id,</if>
<if test="name != null">name,</if>
<if test="address != null">address,</if>
<if test="tel != null">tel,</if>
<if test="email != null">email,</if>
<if test="zipCode != null">zip_code,</if>
<if test="user != null">user,</if>
<if test="phone != null">phone,</if>
<if test="bank != null">bank,</if>
<if test="bankCard != null">bank_card,</if>
<if test="status != null">status,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">#{id},</if>
<if test="name != null">#{name},</if>
<if test="address != null">#{address},</if>
<if test="tel != null">#{tel},</if>
<if test="email != null">#{email},</if>
<if test="zipCode != null">#{zipCode},</if>
<if test="user != null">#{user},</if>
<if test="phone != null">#{phone},</if>
<if test="bank != null">#{bank},</if>
<if test="bankCard != null">#{bankCard},</if>
<if test="status != null">#{status},</if>
</trim>
</insert>
<update id="updateById" parameterType="com.example.entity.Supplier">
update supplier
<set>
<if test="name != null">
name = #{name},
</if>
<if test="address != null">
address = #{address},
</if>
<if test="tel != null">
tel = #{tel},
</if>
<if test="email != null">
email = #{email},
</if>
<if test="zipCode != null">
zip_code = #{zipCode},
</if>
<if test="user != null">
user = #{user},
</if>
<if test="phone != null">
phone = #{phone},
</if>
<if test="bank != null">
bank = #{bank},
</if>
<if test="bankCard != null">
bank_card = #{bankCard},
</if>
<if test="status != null">
status = #{status},
</if>
</set>
where id = #{id}
</update>
</mapper>

@ -0,0 +1,31 @@
server:
port: 9090
# 数据库配置
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
username: root #你本地的数据库用户名
password: 123456 #你本地的数据库密码
url: jdbc:mysql://localhost:3306/psi_manager?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
type-aliases-package: com.example.entity
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
map-underscore-to-camel-case: true
# 分页
pagehelper:
helper-dialect: mysql
reasonable: true
support-methods-arguments: true
params: count=countSql
ip: localhost

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

Loading…
Cancel
Save