5.30测试源代码
`package com.example.test.controller;
import com.example.test.entity.;
import com.example.test.service.AdminService;
import com.example.test.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.;
import jakarta.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
-
管理员控制器,提供对所有表的增删改查操作
*/
@RestController
@RequestMapping("/api/admin")
public class AdminController {private final UserService userService;
private final AdminService adminService;@Autowired
public AdminController(UserService userService, AdminService adminService) {
this.userService = userService;
this.adminService = adminService;
}/**
- 检查管理员权限
*/
private boolean checkAdminPermission(HttpSession session) {
User currentUser = (User) session.getAttribute("currentUser");
return currentUser != null && currentUser.isAdmin();
}
/**
- 获取未授权响应
*/
private ResponseEntity<?> getUnauthorizedResponse() {
Map<String, String> response = new HashMap<>();
response.put("message", "未授权的操作,需要管理员权限");
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(response);
}
/**
-
获取指定实体的所有记录
*/
@GetMapping("/{entityName}")
public ResponseEntity<?> getAllEntities(
@PathVariable String entityName,
HttpSession session) {// 检查管理员权限
if (!checkAdminPermission(session)) {
return getUnauthorizedResponse();
}try {
// 根据实体名称获取对应的类
Class<?> entityClass = adminService.getEntityClassByName(entityName);
if (entityClass == null) {
Map<String, String> response = new HashMap<>();
response.put("message", "实体不存在: " + entityName);
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(response);
}// 查询所有记录
List<?> entities = adminService.findAll(entityClass);
return ResponseEntity.ok(entities);} catch (Exception e) {
Map<String, String> response = new HashMap<>();
response.put("message", "查询失败: " + e.getMessage());
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response);
}
}
/**
-
根据ID获取指定实体的记录
*/
@GetMapping("/{entityName}/{id}")
public ResponseEntity<?> getEntityById(
@PathVariable String entityName,
@PathVariable Long id,
HttpSession session) {// 检查管理员权限
if (!checkAdminPermission(session)) {
return getUnauthorizedResponse();
}try {
// 根据实体名称获取对应的类
Class<?> entityClass = adminService.getEntityClassByName(entityName);
if (entityClass == null) {
Map<String, String> response = new HashMap<>();
response.put("message", "实体不存在: " + entityName);
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(response);
}// 查询指定ID的记录
Object entity = adminService.findById(entityClass, id);
if (entity == null) {
Map<String, String> response = new HashMap<>();
response.put("message", "未找到ID为: " + id + " 的记录");
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(response);
}return ResponseEntity.ok(entity);
} catch (Exception e) {
Map<String, String> response = new HashMap<>();
response.put("message", "查询失败: " + e.getMessage());
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response);
}
}
/**
-
创建实体记录
*/
@PostMapping("/{entityName}")
public ResponseEntity<?> createEntity(
@PathVariable String entityName,
@RequestBody Object entityData,
HttpSession session) {// 检查管理员权限
if (!checkAdminPermission(session)) {
return getUnauthorizedResponse();
}try {
// 保存实体
Object savedEntity = adminService.save(entityData);
return ResponseEntity.status(HttpStatus.CREATED).body(savedEntity);} catch (Exception e) {
Map<String, String> response = new HashMap<>();
response.put("message", "创建失败: " + e.getMessage());
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response);
}
}
/**
-
更新实体记录
*/
@PutMapping("/{entityName}/{id}")
public ResponseEntity<?> updateEntity(
@PathVariable String entityName,
@PathVariable Long id,
@RequestBody Object entityData,
HttpSession session) {// 检查管理员权限
if (!checkAdminPermission(session)) {
return getUnauthorizedResponse();
}try {
// 根据实体名称获取对应的类
Class<?> entityClass = adminService.getEntityClassByName(entityName);
if (entityClass == null) {
Map<String, String> response = new HashMap<>();
response.put("message", "实体不存在: " + entityName);
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(response);
}// 查询指定ID的记录
Object entity = adminService.findById(entityClass, id);
if (entity == null) {
Map<String, String> response = new HashMap<>();
response.put("message", "未找到ID为: " + id + " 的记录");
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(response);
}// 更新实体
Object updatedEntity = adminService.save(entityData);
return ResponseEntity.ok(updatedEntity);} catch (Exception e) {
Map<String, String> response = new HashMap<>();
response.put("message", "更新失败: " + e.getMessage());
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response);
}
}
/**
-
删除实体记录
*/
@DeleteMapping("/{entityName}/{id}")
public ResponseEntity<?> deleteEntity(
@PathVariable String entityName,
@PathVariable Long id,
HttpSession session) {// 检查管理员权限
if (!checkAdminPermission(session)) {
return getUnauthorizedResponse();
}try {
// 根据实体名称获取对应的类
Class<?> entityClass = adminService.getEntityClassByName(entityName);
if (entityClass == null) {
Map<String, String> response = new HashMap<>();
response.put("message", "实体不存在: " + entityName);
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(response);
}// 查询指定ID的记录
Object entity = adminService.findById(entityClass, id);
if (entity == null) {
Map<String, String> response = new HashMap<>();
response.put("message", "未找到ID为: " + id + " 的记录");
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(response);
}// 删除实体
adminService.delete(entityClass, id);Map<String, String> response = new HashMap<>();
response.put("message", "记录已成功删除");
return ResponseEntity.ok(response);} catch (Exception e) {
Map<String, String> response = new HashMap<>();
response.put("message", "删除失败: " + e.getMessage());
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response);
}
}
}package com.example.test.controller;
- 检查管理员权限
import org.springframework.boot.web.error.ErrorAttributeOptions;
import org.springframework.boot.web.servlet.error.ErrorAttributes;
import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.request.ServletWebRequest;
import org.springframework.web.context.request.WebRequest;
import jakarta.servlet.http.HttpServletRequest;
import java.util.Map;
/**
-
自定义错误控制器
-
处理应用程序中的错误,提供友好的错误页面
*/
@Controller
public class CustomErrorController implements ErrorController {private final ErrorAttributes errorAttributes;
public CustomErrorController(ErrorAttributes errorAttributes) {
this.errorAttributes = errorAttributes;
}/**
-
处理HTML请求的错误页面
*/
@RequestMapping(value = "/error", produces = "text/html")
public String errorHtml(HttpServletRequest request, Model model) {
// 获取错误属性
WebRequest webRequest = new ServletWebRequest(request);
Map<String, Object> errorAttributes = this.errorAttributes.getErrorAttributes(
webRequest, ErrorAttributeOptions.defaults());// 将错误属性添加到模型中
model.addAllAttributes(errorAttributes);// 获取HTTP状态码
HttpStatus status = getStatus(request);
model.addAttribute("status", status.value());
model.addAttribute("error", status.getReasonPhrase());// 返回错误视图
return "error";
}
/**
-
处理API请求的错误响应
*/
@RequestMapping(value = "/error")
@ResponseBody
public ResponseEntity<Map<String, Object>> error(HttpServletRequest request) {
// 获取错误属性
WebRequest webRequest = new ServletWebRequest(request);
Map<String, Object> body = this.errorAttributes.getErrorAttributes(
webRequest, ErrorAttributeOptions.defaults());// 获取HTTP状态码
HttpStatus status = getStatus(request);// 返回错误响应
return new ResponseEntity<>(body, status);
}
/**
- 获取HTTP状态码
*/
private HttpStatus getStatus(HttpServletRequest request) {
Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code");
if (statusCode == null) {
return HttpStatus.INTERNAL_SERVER_ERROR;
}
try {
return HttpStatus.valueOf(statusCode);
} catch (Exception ex) {
return HttpStatus.INTERNAL_SERVER_ERROR;
}
}
// 在Spring Boot 3.x中,ErrorController接口不再要求实现getErrorPath方法
}package com.example.test.controller; -
import com.example.test.entity.User;
import com.example.test.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@RestController
@RequestMapping("/api/users")
public class UserController {
private final UserService userService;
@Autowired
public UserController(UserService userService) {
this.userService = userService;
}
// 创建用户
@PostMapping
public ResponseEntity
User createdUser = userService.createUser(user);
return new ResponseEntity<>(createdUser, HttpStatus.CREATED);
}
// 用户登录
@PostMapping("/login")
public ResponseEntity<?> login(@RequestParam String username, @RequestParam String password) {
User user = userService.login(username, password);
if (user != null) {
return ResponseEntity.ok(user);
} else {
Map<String, String> response = new HashMap<>();
response.put("message", "用户名或密码错误");
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(response);
}
}
// 获取所有用户
@GetMapping
public ResponseEntity<List
List
return ResponseEntity.ok(users);
}
// 根据用户名查询用户
@GetMapping("/username/{username}")
public ResponseEntity<?> getUserByUsername(@PathVariable String username) {
User user = userService.findUserByUsername(username);
if (user != null) {
return ResponseEntity.ok(user);
} else {
Map<String, String> response = new HashMap<>();
response.put("message", "未找到用户名为: " + username + " 的用户");
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(response);
}
}
// 根据邮箱查询用户
@GetMapping("/email/{email}")
public ResponseEntity<?> getUserByEmail(@PathVariable String email) {
User user = userService.findUserByEmail(email);
if (user != null) {
return ResponseEntity.ok(user);
} else {
Map<String, String> response = new HashMap<>();
response.put("message", "未找到邮箱为: " + email + " 的用户");
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(response);
}
}
// 根据电话查询用户
@GetMapping("/phone/{phone}")
public ResponseEntity<?> getUserByPhone(@PathVariable String phone) {
User user = userService.findUserByPhone(phone);
if (user != null) {
return ResponseEntity.ok(user);
} else {
Map<String, String> response = new HashMap<>();
response.put("message", "未找到电话为: " + phone + " 的用户");
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(response);
}
}
// 根据ID获取用户
@GetMapping("/{id}")
public ResponseEntity<?> getUserById(@PathVariable Long id) {
Optional
if (userOptional.isPresent()) {
return ResponseEntity.ok(userOptional.get());
} else {
Map<String, String> response = new HashMap<>();
response.put("message", "未找到ID为: " + id + " 的用户");
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(response);
}
}
// 根据部门查询用户列表
@GetMapping("/department/{department}")
public ResponseEntity<List
List
return ResponseEntity.ok(users);
}
// 根据职位查询用户列表
@GetMapping("/position/{position}")
public ResponseEntity<List
List
return ResponseEntity.ok(users);
}
// 根据部门和职位查询用户列表
@GetMapping("/department/{department}/position/{position}")
public ResponseEntity<List
@PathVariable String department,
@PathVariable String position) {
List
return ResponseEntity.ok(users);
}
// 根据状态查询用户列表
@GetMapping("/status/{status}")
public ResponseEntity<List
List
return ResponseEntity.ok(users);
}
// 根据真实姓名模糊查询
@GetMapping("/search/realname")
public ResponseEntity<List
List
return ResponseEntity.ok(users);
}
// 查询指定时间之后创建的用户
@GetMapping("/created-after")
public ResponseEntity<List
@RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime dateTime) {
List
return ResponseEntity.ok(users);
}
// 查询指定时间之后登录的用户
@GetMapping("/login-after")
public ResponseEntity<List
@RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime dateTime) {
List
return ResponseEntity.ok(users);
}
// 更新用户
@PutMapping("/{id}")
public ResponseEntity<?> updateUser(@PathVariable Long id, @RequestBody User userDetails) {
Optional
if (userOptional.isPresent()) {
User user = userOptional.get();
// 保存原始用户名,确保不被修改
String originalUsername = user.getUsername();
// 更新用户信息
if (userDetails.getPassword() != null) {
user.setPassword(userDetails.getPassword());
}
if (userDetails.getRealName() != null) {
user.setRealName(userDetails.getRealName());
}
if (userDetails.getEmail() != null) {
user.setEmail(userDetails.getEmail());
}
if (userDetails.getPhone() != null) {
user.setPhone(userDetails.getPhone());
}
if (userDetails.getDepartment() != null) {
user.setDepartment(userDetails.getDepartment());
}
if (userDetails.getPosition() != null) {
user.setPosition(userDetails.getPosition());
}
if (userDetails.getStatus() != null) {
user.setStatus(userDetails.getStatus());
}
// 确保用户名不变
user.setUsername(originalUsername);
User updatedUser = userService.updateUser(user);
return ResponseEntity.ok(updatedUser);
} else {
Map<String, String> response = new HashMap<>();
response.put("message", "未找到ID为: " + id + " 的用户");
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(response);
}
}
// 启用用户
@PatchMapping("/{id}/enable")
public ResponseEntity<?> enableUser(@PathVariable Long id) {
User user = userService.enableUser(id);
if (user != null) {
return ResponseEntity.ok(user);
} else {
Map<String, String> response = new HashMap<>();
response.put("message", "未找到ID为: " + id + " 的用户");
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(response);
}
}
// 禁用用户
@PatchMapping("/{id}/disable")
public ResponseEntity<?> disableUser(@PathVariable Long id) {
User user = userService.disableUser(id);
if (user != null) {
return ResponseEntity.ok(user);
} else {
Map<String, String> response = new HashMap<>();
response.put("message", "未找到ID为: " + id + " 的用户");
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(response);
}
}
// 删除用户
@DeleteMapping("/{id}")
public ResponseEntity<?> deleteUser(@PathVariable Long id) {
return userService.findUserById(id)
.map(user -> {
userService.deleteUser(id);
Map<String, String> response = new HashMap<>();
response.put("message", "用户已成功删除");
return ResponseEntity.ok(response);
})
.orElseGet(() -> {
Map<String, String> response = new HashMap<>();
response.put("message", "未找到ID为: " + id + " 的用户");
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(response);
});
}
}package com.example.test.controller;
import com.example.test.entity.User;
import com.example.test.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import jakarta.servlet.http.HttpSession;
import java.util.List;
/**
-
Web页面控制器,处理HTML页面的请求
*/
@Controller
public class WebController {private final UserService userService;
@Autowired
public WebController(UserService userService) {
this.userService = userService;
}/**
- 首页重定向到登录页
*/
@GetMapping("/")
public String index() {
return "redirect:/login";
}
/**
- 显示登录页面
*/
@GetMapping("/login")
public String showLoginPage() {
return "login";
}
/**
-
处理登录请求
*/
@PostMapping("/login")
public String processLogin(@RequestParam String username,
@RequestParam String password,
RedirectAttributes redirectAttributes,
HttpSession session) {
User user = userService.login(username, password);
if (user != null) {
// 登录成功,将用户信息存储在session中
session.setAttribute("currentUser", user);// 根据用户角色跳转到不同页面
if (user.isAdmin()) {
return "redirect:/admin/dashboard";
} else {
return "redirect:/dashboard";
}
} else {
// 登录失败,添加错误消息并返回登录页
redirectAttributes.addFlashAttribute("errorMessage", "用户名或密码错误");
return "redirect:/login";
}
}
/**
- 显示注册页面
*/
@GetMapping("/register")
public String showRegisterPage() {
return "redirect:/login?register";
}
/**
-
处理注册请求
*/
@PostMapping("/register")
public String processRegistration(@ModelAttribute User user,
RedirectAttributes redirectAttributes) {
// 检查用户名是否已存在
if (userService.findUserByUsername(user.getUsername()) != null) {
redirectAttributes.addFlashAttribute("errorMessage", "用户名已存在");
return "redirect:/login?register";
}// 检查邮箱是否已存在
if (userService.findUserByEmail(user.getEmail()) != null) {
redirectAttributes.addFlashAttribute("errorMessage", "邮箱已被注册");
return "redirect:/login?register";
}// 检查手机号是否已存在
if (user.getPhone() != null && userService.findUserByPhone(user.getPhone()) != null) {
redirectAttributes.addFlashAttribute("errorMessage", "手机号已被注册");
return "redirect:/login?register";
}// 设置用户状态为启用
user.setStatus(true);// 保存用户
try {
userService.createUser(user);
redirectAttributes.addFlashAttribute("success", "注册成功,请登录");
return "redirect:/login";
} catch (Exception e) {
redirectAttributes.addFlashAttribute("errorMessage", "注册失败: " + e.getMessage());
return "redirect:/login?register";
}
}
/**
- 用户仪表盘页面
*/
@GetMapping("/dashboard")
public String dashboard(HttpSession session, Model model) {
// 验证用户是否已登录
User currentUser = (User) session.getAttribute("currentUser");
if (currentUser == null) {
// 用户未登录,重定向到登录页
return "redirect:/login";
}
// 将用户信息添加到模型中,供模板使用
model.addAttribute("currentUser", currentUser);
return "dashboard";
}
/**
-
管理员仪表盘页面
*/
@GetMapping("/admin/dashboard")
public String adminDashboard(HttpSession session, Model model) {
// 验证用户是否已登录且是管理员
User currentUser = (User) session.getAttribute("currentUser");
if (currentUser == null) {
// 用户未登录,重定向到登录页
return "redirect:/login";
}if (!currentUser.isAdmin()) {
// 用户不是管理员,重定向到普通用户仪表盘
return "redirect:/dashboard";
}// 将用户信息添加到模型中,供模板使用
model.addAttribute("currentUser", currentUser);
return "admin/dashboard";
}
/**
-
管理员用户管理页面
*/
@GetMapping("/admin/users")
public String adminUserManagement(HttpSession session, Model model) {
// 验证用户是否已登录且是管理员
User currentUser = (User) session.getAttribute("currentUser");
if (currentUser == null) {
// 用户未登录,重定向到登录页
return "redirect:/login";
}if (!currentUser.isAdmin()) {
// 用户不是管理员,重定向到普通用户仪表盘
return "redirect:/dashboard";
}// 获取所有用户列表
Listusers = userService.findAllUsers(); // 将用户信息添加到模型中,供模板使用
model.addAttribute("currentUser", currentUser);
model.addAttribute("users", users);
return "admin/users";
}
/**
- 退出登录
*/
@GetMapping("/logout")
public String logout(HttpSession session) {
// 清除session
session.invalidate();
return "redirect:/login";
}
}package com.example.test.entity;
- 首页重定向到登录页
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import java.time.LocalDateTime;
@Entity
@Table(name = "contact_form")
public class ContactForm {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "form_number", nullable = false, unique = true, length = 50)
private String formNumber;
@ManyToOne
@JoinColumn(name = "order_id")
private SalesOrder order;
@Column(name = "order_number", length = 50)
private String orderNumber;
@ManyToOne
@JoinColumn(name = "customer_id")
private User customer;
@Column(name = "customer_name", length = 100)
private String customerName;
@Column(name = "contact_type", length = 20)
private String contactType; // 订单咨询、产品咨询、投诉、建议、其他
@Column(name = "contact_content", nullable = false, length = 1000)
private String contactContent;
@Column(name = "contact_status", length = 20)
private String contactStatus; // 待处理、处理中、已完成
@Column(name = "priority", length = 10)
private String priority; // 高、中、低
@ManyToOne
@JoinColumn(name = "handler_id")
private User handler;
@Column(name = "handler_name", length = 50)
private String handlerName;
@Column(name = "handling_result", length = 1000)
private String handlingResult;
@Column(name = "handling_time")
private LocalDateTime handlingTime;
@Column(name = "create_time")
private LocalDateTime createTime;
@Column(name = "update_time")
private LocalDateTime updateTime;
@Column(name = "created_by")
private Long createdBy;
@Column(name = "updated_by")
private Long updatedBy;
// 默认构造函数
public ContactForm() {
}
// 带基本参数的构造函数
public ContactForm(String formNumber, String contactType, String contactContent) {
this.formNumber = formNumber;
this.contactType = contactType;
this.contactContent = contactContent;
this.contactStatus = "待处理";
this.priority = "中";
this.createTime = LocalDateTime.now();
this.updateTime = LocalDateTime.now();
}
// 带订单和客户的构造函数
public ContactForm(String formNumber, SalesOrder order, User customer, String contactType, String contactContent) {
this(formNumber, contactType, contactContent);
this.order = order;
if (order != null) {
this.orderNumber = order.getOrderNumber();
}
this.customer = customer;
this.customerName = customer != null ? customer.getRealName() : null;
}
// Getters and Setters
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getFormNumber() {
return formNumber;
}
public void setFormNumber(String formNumber) {
this.formNumber = formNumber;
}
public SalesOrder getOrder() {
return order;
}
public void setOrder(SalesOrder order) {
this.order = order;
if (order != null) {
this.orderNumber = order.getOrderNumber();
}
}
public String getOrderNumber() {
return orderNumber;
}
public void setOrderNumber(String orderNumber) {
this.orderNumber = orderNumber;
}
public User getCustomer() {
return customer;
}
public void setCustomer(User customer) {
this.customer = customer;
this.customerName = customer != null ? customer.getRealName() : null;
}
public String getCustomerName() {
return customerName;
}
public void setCustomerName(String customerName) {
this.customerName = customerName;
}
public String getContactType() {
return contactType;
}
public void setContactType(String contactType) {
this.contactType = contactType;
}
public String getContactContent() {
return contactContent;
}
public void setContactContent(String contactContent) {
this.contactContent = contactContent;
}
public String getContactStatus() {
return contactStatus;
}
public void setContactStatus(String contactStatus) {
this.contactStatus = contactStatus;
}
public String getPriority() {
return priority;
}
public void setPriority(String priority) {
this.priority = priority;
}
public User getHandler() {
return handler;
}
public void setHandler(User handler) {
this.handler = handler;
this.handlerName = handler != null ? handler.getRealName() : null;
}
public String getHandlerName() {
return handlerName;
}
public void setHandlerName(String handlerName) {
this.handlerName = handlerName;
}
public String getHandlingResult() {
return handlingResult;
}
public void setHandlingResult(String handlingResult) {
this.handlingResult = handlingResult;
}
public LocalDateTime getHandlingTime() {
return handlingTime;
}
public void setHandlingTime(LocalDateTime handlingTime) {
this.handlingTime = handlingTime;
}
public LocalDateTime getCreateTime() {
return createTime;
}
public void setCreateTime(LocalDateTime createTime) {
this.createTime = createTime;
}
public LocalDateTime getUpdateTime() {
return updateTime;
}
public void setUpdateTime(LocalDateTime updateTime) {
this.updateTime = updateTime;
}
public Long getCreatedBy() {
return createdBy;
}
public void setCreatedBy(Long createdBy) {
this.createdBy = createdBy;
}
public Long getUpdatedBy() {
return updatedBy;
}
public void setUpdatedBy(Long updatedBy) {
this.updatedBy = updatedBy;
}
@Override
public String toString() {
return "ContactForm{" +
"id=" + id +
", formNumber='" + formNumber + ''' +
", orderNumber='" + orderNumber + ''' +
", customerName='" + customerName + ''' +
", contactType='" + contactType + ''' +
", contactStatus='" + contactStatus + ''' +
'}';
}
}package com.example.test.entity;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import java.math.BigDecimal;
import java.time.LocalDateTime;
@Entity
@Table(name = "delivery_order")
public class DeliveryOrder {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "delivery_number", nullable = false, unique = true, length = 50)
private String deliveryNumber;
@ManyToOne
@JoinColumn(name = "order_id")
private SalesOrder order;
@Column(name = "order_number", length = 50)
private String orderNumber;
@ManyToOne
@JoinColumn(name = "customer_id")
private User customer;
@Column(name = "customer_name", length = 100)
private String customerName;
@Column(name = "contact_address", length = 255)
private String contactAddress;
@Column(name = "delivery_date")
private LocalDateTime deliveryDate;
@Column(name = "shipping_method", length = 50)
private String shippingMethod;
@Column(name = "tracking_number", length = 50)
private String trackingNumber;
@Column(name = "delivery_status", length = 20)
private String deliveryStatus; // 待发货、已发货、已签收
@Column(name = "total_quantity")
private Integer totalQuantity;
@Column(name = "total_amount", precision = 10, scale = 2)
private BigDecimal totalAmount;
@Column(name = "remarks", length = 500)
private String remarks;
@ManyToOne
@JoinColumn(name = "handler_id")
private User handler;
@Column(name = "handler_name", length = 50)
private String handlerName;
@Column(name = "create_time")
private LocalDateTime createTime;
@Column(name = "update_time")
private LocalDateTime updateTime;
@Column(name = "created_by")
private Long createdBy;
@Column(name = "updated_by")
private Long updatedBy;
// 默认构造函数
public DeliveryOrder() {
}
// 带基本参数的构造函数
public DeliveryOrder(String deliveryNumber, SalesOrder order) {
this.deliveryNumber = deliveryNumber;
this.order = order;
if (order != null) {
this.orderNumber = order.getOrderNumber();
this.customer = order.getCustomer();
this.customerName = order.getCustomerName();
this.contactAddress = order.getContactAddress();
this.shippingMethod = order.getShippingMethod();
}
this.deliveryStatus = "待发货";
this.createTime = LocalDateTime.now();
this.updateTime = LocalDateTime.now();
}
// Getters and Setters
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getDeliveryNumber() {
return deliveryNumber;
}
public void setDeliveryNumber(String deliveryNumber) {
this.deliveryNumber = deliveryNumber;
}
public SalesOrder getOrder() {
return order;
}
public void setOrder(SalesOrder order) {
this.order = order;
if (order != null) {
this.orderNumber = order.getOrderNumber();
this.customer = order.getCustomer();
this.customerName = order.getCustomerName();
this.contactAddress = order.getContactAddress();
this.shippingMethod = order.getShippingMethod();
}
}
public String getOrderNumber() {
return orderNumber;
}
public void setOrderNumber(String orderNumber) {
this.orderNumber = orderNumber;
}
public User getCustomer() {
return customer;
}
public void setCustomer(User customer) {
this.customer = customer;
this.customerName = customer != null ? customer.getRealName() : null;
}
public String getCustomerName() {
return customerName;
}
public void setCustomerName(String customerName) {
this.customerName = customerName;
}
public String getContactAddress() {
return contactAddress;
}
public void setContactAddress(String contactAddress) {
this.contactAddress = contactAddress;
}
public LocalDateTime getDeliveryDate() {
return deliveryDate;
}
public void setDeliveryDate(LocalDateTime deliveryDate) {
this.deliveryDate = deliveryDate;
}
public String getShippingMethod() {
return shippingMethod;
}
public void setShippingMethod(String shippingMethod) {
this.shippingMethod = shippingMethod;
}
public String getTrackingNumber() {
return trackingNumber;
}
public void setTrackingNumber(String trackingNumber) {
this.trackingNumber = trackingNumber;
}
public String getDeliveryStatus() {
return deliveryStatus;
}
public void setDeliveryStatus(String deliveryStatus) {
this.deliveryStatus = deliveryStatus;
}
public Integer getTotalQuantity() {
return totalQuantity;
}
public void setTotalQuantity(Integer totalQuantity) {
this.totalQuantity = totalQuantity;
}
public BigDecimal getTotalAmount() {
return totalAmount;
}
public void setTotalAmount(BigDecimal totalAmount) {
this.totalAmount = totalAmount;
}
public String getRemarks() {
return remarks;
}
public void setRemarks(String remarks) {
this.remarks = remarks;
}
public User getHandler() {
return handler;
}
public void setHandler(User handler) {
this.handler = handler;
this.handlerName = handler != null ? handler.getRealName() : null;
}
public String getHandlerName() {
return handlerName;
}
public void setHandlerName(String handlerName) {
this.handlerName = handlerName;
}
public LocalDateTime getCreateTime() {
return createTime;
}
public void setCreateTime(LocalDateTime createTime) {
this.createTime = createTime;
}
public LocalDateTime getUpdateTime() {
return updateTime;
}
public void setUpdateTime(LocalDateTime updateTime) {
this.updateTime = updateTime;
}
public Long getCreatedBy() {
return createdBy;
}
public void setCreatedBy(Long createdBy) {
this.createdBy = createdBy;
}
public Long getUpdatedBy() {
return updatedBy;
}
public void setUpdatedBy(Long updatedBy) {
this.updatedBy = updatedBy;
}
@Override
public String toString() {
return "DeliveryOrder{" +
"id=" + id +
", deliveryNumber='" + deliveryNumber + ''' +
", orderNumber='" + orderNumber + ''' +
", customerName='" + customerName + ''' +
", deliveryDate=" + deliveryDate +
", deliveryStatus='" + deliveryStatus + ''' +
'}';
}
}package com.example.test.entity;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import java.math.BigDecimal;
import java.time.LocalDateTime;
@Entity
@Table(name = "delivery_statistics")
public class DeliveryStatistics {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "statistics_year")
private Integer statisticsYear;
@Column(name = "statistics_month")
private Integer statisticsMonth;
@Column(name = "statistics_quarter")
private Integer statisticsQuarter;
@Column(name = "customer_name", length = 100)
private String customerName;
@Column(name = "product_code", length = 50)
private String productCode;
@Column(name = "product_name", length = 100)
private String productName;
@Column(name = "product_model", length = 50)
private String productModel;
@Column(name = "delivery_quantity")
private Integer deliveryQuantity;
@Column(name = "delivery_amount", precision = 10, scale = 2)
private BigDecimal deliveryAmount;
@Column(name = "on_time_delivery_rate", precision = 5, scale = 2)
private BigDecimal onTimeDeliveryRate; // 准时交付率
@Column(name = "customer_satisfaction_rate", precision = 5, scale = 2)
private BigDecimal customerSatisfactionRate; // 客户满意度
@Column(name = "create_time")
private LocalDateTime createTime;
@Column(name = "update_time")
private LocalDateTime updateTime;
// 默认构造函数
public DeliveryStatistics() {
}
// 带基本参数的构造函数
public DeliveryStatistics(Integer statisticsYear, Integer statisticsMonth) {
this.statisticsYear = statisticsYear;
this.statisticsMonth = statisticsMonth;
if (statisticsMonth != null) {
this.statisticsQuarter = (statisticsMonth - 1) / 3 + 1;
}
this.createTime = LocalDateTime.now();
this.updateTime = LocalDateTime.now();
}
// Getters and Setters
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Integer getStatisticsYear() {
return statisticsYear;
}
public void setStatisticsYear(Integer statisticsYear) {
this.statisticsYear = statisticsYear;
}
public Integer getStatisticsMonth() {
return statisticsMonth;
}
public void setStatisticsMonth(Integer statisticsMonth) {
this.statisticsMonth = statisticsMonth;
if (statisticsMonth != null) {
this.statisticsQuarter = (statisticsMonth - 1) / 3 + 1;
}
}
public Integer getStatisticsQuarter() {
return statisticsQuarter;
}
public void setStatisticsQuarter(Integer statisticsQuarter) {
this.statisticsQuarter = statisticsQuarter;
}
public String getCustomerName() {
return customerName;
}
public void setCustomerName(String customerName) {
this.customerName = customerName;
}
public String getProductCode() {
return productCode;
}
public void setProductCode(String productCode) {
this.productCode = productCode;
}
public String getProductName() {
return productName;
}
public void setProductName(String productName) {
this.productName = productName;
}
public String getProductModel() {
return productModel;
}
public void setProductModel(String productModel) {
this.productModel = productModel;
}
public Integer getDeliveryQuantity() {
return deliveryQuantity;
}
public void setDeliveryQuantity(Integer deliveryQuantity) {
this.deliveryQuantity = deliveryQuantity;
}
public BigDecimal getDeliveryAmount() {
return deliveryAmount;
}
public void setDeliveryAmount(BigDecimal deliveryAmount) {
this.deliveryAmount = deliveryAmount;
}
public BigDecimal getOnTimeDeliveryRate() {
return onTimeDeliveryRate;
}
public void setOnTimeDeliveryRate(BigDecimal onTimeDeliveryRate) {
this.onTimeDeliveryRate = onTimeDeliveryRate;
}
public BigDecimal getCustomerSatisfactionRate() {
return customerSatisfactionRate;
}
public void setCustomerSatisfactionRate(BigDecimal customerSatisfactionRate) {
this.customerSatisfactionRate = customerSatisfactionRate;
}
public LocalDateTime getCreateTime() {
return createTime;
}
public void setCreateTime(LocalDateTime createTime) {
this.createTime = createTime;
}
public LocalDateTime getUpdateTime() {
return updateTime;
}
public void setUpdateTime(LocalDateTime updateTime) {
this.updateTime = updateTime;
}
@Override
public String toString() {
return "DeliveryStatistics{" +
"id=" + id +
", statisticsYear=" + statisticsYear +
", statisticsMonth=" + statisticsMonth +
", customerName='" + customerName + ''' +
", productName='" + productName + ''' +
", deliveryQuantity=" + deliveryQuantity +
", deliveryAmount=" + deliveryAmount +
'}';
}
}package com.example.test.entity;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import java.math.BigDecimal;
import java.time.LocalDateTime;
@Entity
@Table(name = "forecast_plan")
public class ForecastPlan {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "plan_number", nullable = false, unique = true, length = 50)
private String planNumber;
@Column(name = "plan_name", length = 100)
private String planName;
@Column(name = "plan_year")
private Integer planYear;
@Column(name = "plan_month")
private Integer planMonth;
@Column(name = "plan_quarter")
private Integer planQuarter;
@ManyToOne
@JoinColumn(name = "customer_id")
private User customer;
@Column(name = "customer_name", length = 100)
private String customerName;
@Column(name = "product_code", length = 50)
private String productCode;
@Column(name = "product_name", length = 100)
private String productName;
@Column(name = "forecast_quantity")
private Integer forecastQuantity;
@Column(name = "actual_quantity")
private Integer actualQuantity;
@Column(name = "forecast_amount", precision = 10, scale = 2)
private BigDecimal forecastAmount;
@Column(name = "actual_amount", precision = 10, scale = 2)
private BigDecimal actualAmount;
@Column(name = "plan_status", length = 20)
private String planStatus; // 草稿、已提交、已审核、已完成
@Column(name = "remarks", length = 500)
private String remarks;
@Column(name = "create_time")
private LocalDateTime createTime;
@Column(name = "update_time")
private LocalDateTime updateTime;
@Column(name = "created_by")
private Long createdBy;
@Column(name = "updated_by")
private Long updatedBy;
// 默认构造函数
public ForecastPlan() {
}
// 带基本参数的构造函数
public ForecastPlan(String planNumber, String planName, Integer planYear, Integer planMonth) {
this.planNumber = planNumber;
this.planName = planName;
this.planYear = planYear;
this.planMonth = planMonth;
if (planMonth != null) {
this.planQuarter = (planMonth - 1) / 3 + 1;
}
this.planStatus = "草稿";
this.createTime = LocalDateTime.now();
this.updateTime = LocalDateTime.now();
}
// Getters and Setters
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getPlanNumber() {
return planNumber;
}
public void setPlanNumber(String planNumber) {
this.planNumber = planNumber;
}
public String getPlanName() {
return planName;
}
public void setPlanName(String planName) {
this.planName = planName;
}
public Integer getPlanYear() {
return planYear;
}
public void setPlanYear(Integer planYear) {
this.planYear = planYear;
}
public Integer getPlanMonth() {
return planMonth;
}
public void setPlanMonth(Integer planMonth) {
this.planMonth = planMonth;
if (planMonth != null) {
this.planQuarter = (planMonth - 1) / 3 + 1;
}
}
public Integer getPlanQuarter() {
return planQuarter;
}
public void setPlanQuarter(Integer planQuarter) {
this.planQuarter = planQuarter;
}
public User getCustomer() {
return customer;
}
public void setCustomer(User customer) {
this.customer = customer;
this.customerName = customer != null ? customer.getRealName() : null;
}
public String getCustomerName() {
return customerName;
}
public void setCustomerName(String customerName) {
this.customerName = customerName;
}
public String getProductCode() {
return productCode;
}
public void setProductCode(String productCode) {
this.productCode = productCode;
}
public String getProductName() {
return productName;
}
public void setProductName(String productName) {
this.productName = productName;
}
public Integer getForecastQuantity() {
return forecastQuantity;
}
public void setForecastQuantity(Integer forecastQuantity) {
this.forecastQuantity = forecastQuantity;
}
public Integer getActualQuantity() {
return actualQuantity;
}
public void setActualQuantity(Integer actualQuantity) {
this.actualQuantity = actualQuantity;
}
public BigDecimal getForecastAmount() {
return forecastAmount;
}
public void setForecastAmount(BigDecimal forecastAmount) {
this.forecastAmount = forecastAmount;
}
public BigDecimal getActualAmount() {
return actualAmount;
}
public void setActualAmount(BigDecimal actualAmount) {
this.actualAmount = actualAmount;
}
public String getPlanStatus() {
return planStatus;
}
public void setPlanStatus(String planStatus) {
this.planStatus = planStatus;
}
public String getRemarks() {
return remarks;
}
public void setRemarks(String remarks) {
this.remarks = remarks;
}
public LocalDateTime getCreateTime() {
return createTime;
}
public void setCreateTime(LocalDateTime createTime) {
this.createTime = createTime;
}
public LocalDateTime getUpdateTime() {
return updateTime;
}
public void setUpdateTime(LocalDateTime updateTime) {
this.updateTime = updateTime;
}
public Long getCreatedBy() {
return createdBy;
}
public void setCreatedBy(Long createdBy) {
this.createdBy = createdBy;
}
public Long getUpdatedBy() {
return updatedBy;
}
public void setUpdatedBy(Long updatedBy) {
this.updatedBy = updatedBy;
}
@Override
public String toString() {
return "ForecastPlan{" +
"id=" + id +
", planNumber='" + planNumber + ''' +
", planName='" + planName + ''' +
", planYear=" + planYear +
", planMonth=" + planMonth +
", customerName='" + customerName + ''' +
", forecastQuantity=" + forecastQuantity +
'}';
}
}package com.example.test.entity;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import java.time.LocalDateTime;
@Entity
@Table(name = "missing_product")
public class MissingProduct {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToOne
@JoinColumn(name = "order_id")
private SalesOrder order;
@ManyToOne
@JoinColumn(name = "order_product_id")
private OrderProduct orderProduct;
@Column(name = "product_code", nullable = false, length = 50)
private String productCode;
@Column(name = "product_name", length = 100)
private String productName;
@Column(name = "product_model", length = 50)
private String productModel;
@Column(name = "unit", length = 20)
private String unit;
@Column(name = "missing_quantity", nullable = false)
private Integer missingQuantity;
@Column(name = "expected_arrival_date")
private LocalDateTime expectedArrivalDate;
@Column(name = "actual_arrival_date")
private LocalDateTime actualArrivalDate;
@Column(name = "status", length = 20)
private String status; // 缺货中、已到货、已取消
@Column(name = "remarks", length = 255)
private String remarks;
@Column(name = "create_time")
private LocalDateTime createTime;
@Column(name = "update_time")
private LocalDateTime updateTime;
// 默认构造函数
public MissingProduct() {
}
// 带基本参数的构造函数
public MissingProduct(SalesOrder order, OrderProduct orderProduct, Integer missingQuantity) {
this.order = order;
this.orderProduct = orderProduct;
this.productCode = orderProduct != null ? orderProduct.getProductCode() : null;
this.productName = orderProduct != null ? orderProduct.getProductName() : null;
this.productModel = orderProduct != null ? orderProduct.getProductModel() : null;
this.unit = orderProduct != null ? orderProduct.getUnit() : null;
this.missingQuantity = missingQuantity;
this.status = "缺货中";
this.createTime = LocalDateTime.now();
this.updateTime = LocalDateTime.now();
}
// Getters and Setters
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public SalesOrder getOrder() {
return order;
}
public void setOrder(SalesOrder order) {
this.order = order;
}
public OrderProduct getOrderProduct() {
return orderProduct;
}
public void setOrderProduct(OrderProduct orderProduct) {
this.orderProduct = orderProduct;
if (orderProduct != null) {
this.productCode = orderProduct.getProductCode();
this.productName = orderProduct.getProductName();
this.productModel = orderProduct.getProductModel();
this.unit = orderProduct.getUnit();
}
}
public String getProductCode() {
return productCode;
}
public void setProductCode(String productCode) {
this.productCode = productCode;
}
public String getProductName() {
return productName;
}
public void setProductName(String productName) {
this.productName = productName;
}
public String getProductModel() {
return productModel;
}
public void setProductModel(String productModel) {
this.productModel = productModel;
}
public String getUnit() {
return unit;
}
public void setUnit(String unit) {
this.unit = unit;
}
public Integer getMissingQuantity() {
return missingQuantity;
}
public void setMissingQuantity(Integer missingQuantity) {
this.missingQuantity = missingQuantity;
}
public LocalDateTime getExpectedArrivalDate() {
return expectedArrivalDate;
}
public void setExpectedArrivalDate(LocalDateTime expectedArrivalDate) {
this.expectedArrivalDate = expectedArrivalDate;
}
public LocalDateTime getActualArrivalDate() {
return actualArrivalDate;
}
public void setActualArrivalDate(LocalDateTime actualArrivalDate) {
this.actualArrivalDate = actualArrivalDate;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getRemarks() {
return remarks;
}
public void setRemarks(String remarks) {
this.remarks = remarks;
}
public LocalDateTime getCreateTime() {
return createTime;
}
public void setCreateTime(LocalDateTime createTime) {
this.createTime = createTime;
}
public LocalDateTime getUpdateTime() {
return updateTime;
}
public void setUpdateTime(LocalDateTime updateTime) {
this.updateTime = updateTime;
}
@Override
public String toString() {
return "MissingProduct{" +
"id=" + id +
", productCode='" + productCode + ''' +
", productName='" + productName + ''' +
", missingQuantity=" + missingQuantity +
", status='" + status + ''' +
'}';
}
}package com.example.test.entity;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import java.time.LocalDateTime;
@Entity
@Table(name = "order_change")
public class OrderChange {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToOne
@JoinColumn(name = "order_id", nullable = false)
private SalesOrder order;
@Column(name = "change_type", nullable = false, length = 20)
private String changeType; // 订单信息变更、产品变更、交期变更、取消订单
@Column(name = "change_content", nullable = false, length = 500)
private String changeContent;
@Column(name = "change_reason", length = 500)
private String changeReason;
@Column(name = "change_status", nullable = false, length = 20)
private String changeStatus; // 待审核、已通过、已拒绝
@ManyToOne
@JoinColumn(name = "applicant_id")
private User applicant;
@Column(name = "applicant_name", length = 50)
private String applicantName;
@Column(name = "apply_time")
private LocalDateTime applyTime;
@ManyToOne
@JoinColumn(name = "reviewer_id")
private User reviewer;
@Column(name = "reviewer_name", length = 50)
private String reviewerName;
@Column(name = "review_time")
private LocalDateTime reviewTime;
@Column(name = "review_comments", length = 500)
private String reviewComments;
// 默认构造函数
public OrderChange() {
}
// 带基本参数的构造函数
public OrderChange(SalesOrder order, String changeType, String changeContent, User applicant) {
this.order = order;
this.changeType = changeType;
this.changeContent = changeContent;
this.changeStatus = "待审核";
this.applicant = applicant;
this.applicantName = applicant != null ? applicant.getRealName() : null;
this.applyTime = LocalDateTime.now();
}
// Getters and Setters
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public SalesOrder getOrder() {
return order;
}
public void setOrder(SalesOrder order) {
this.order = order;
}
public String getChangeType() {
return changeType;
}
public void setChangeType(String changeType) {
this.changeType = changeType;
}
public String getChangeContent() {
return changeContent;
}
public void setChangeContent(String changeContent) {
this.changeContent = changeContent;
}
public String getChangeReason() {
return changeReason;
}
public void setChangeReason(String changeReason) {
this.changeReason = changeReason;
}
public String getChangeStatus() {
return changeStatus;
}
public void setChangeStatus(String changeStatus) {
this.changeStatus = changeStatus;
}
public User getApplicant() {
return applicant;
}
public void setApplicant(User applicant) {
this.applicant = applicant;
this.applicantName = applicant != null ? applicant.getRealName() : null;
}
public String getApplicantName() {
return applicantName;
}
public void setApplicantName(String applicantName) {
this.applicantName = applicantName;
}
public LocalDateTime getApplyTime() {
return applyTime;
}
public void setApplyTime(LocalDateTime applyTime) {
this.applyTime = applyTime;
}
public User getReviewer() {
return reviewer;
}
public void setReviewer(User reviewer) {
this.reviewer = reviewer;
this.reviewerName = reviewer != null ? reviewer.getRealName() : null;
}
public String getReviewerName() {
return reviewerName;
}
public void setReviewerName(String reviewerName) {
this.reviewerName = reviewerName;
}
public LocalDateTime getReviewTime() {
return reviewTime;
}
public void setReviewTime(LocalDateTime reviewTime) {
this.reviewTime = reviewTime;
}
public String getReviewComments() {
return reviewComments;
}
public void setReviewComments(String reviewComments) {
this.reviewComments = reviewComments;
}
// 审核通过方法
public void approve(User reviewer, String comments) {
this.reviewer = reviewer;
this.reviewerName = reviewer != null ? reviewer.getRealName() : null;
this.changeStatus = "已通过";
this.reviewComments = comments;
this.reviewTime = LocalDateTime.now();
}
// 审核拒绝方法
public void reject(User reviewer, String comments) {
this.reviewer = reviewer;
this.reviewerName = reviewer != null ? reviewer.getRealName() : null;
this.changeStatus = "已拒绝";
this.reviewComments = comments;
this.reviewTime = LocalDateTime.now();
}
@Override
public String toString() {
return "OrderChange{" +
"id=" + id +
", changeType='" + changeType + ''' +
", changeStatus='" + changeStatus + ''' +
", applicantName='" + applicantName + ''' +
", applyTime=" + applyTime +
'}';
}
}package com.example.test.entity;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import java.math.BigDecimal;
@Entity
@Table(name = "order_product")
public class OrderProduct {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToOne
@JoinColumn(name = "order_id", nullable = false)
private SalesOrder order;
@Column(name = "product_code", nullable = false, length = 50)
private String productCode;
@Column(name = "product_name", length = 100)
private String productName;
@Column(name = "product_model", length = 50)
private String productModel;
@Column(name = "unit", length = 20)
private String unit;
@Column(name = "quantity", nullable = false)
private Integer quantity;
@Column(name = "unit_price", precision = 10, scale = 2)
private BigDecimal unitPrice;
@Column(name = "total_price", precision = 10, scale = 2)
private BigDecimal totalPrice;
@Column(name = "remarks", length = 255)
private String remarks;
@Column(name = "production_status", length = 20)
private String productionStatus; // 未生产、生产中、已完成
// 默认构造函数
public OrderProduct() {
}
// 带基本参数的构造函数
public OrderProduct(SalesOrder order, String productCode, String productName, String productModel, String unit, Integer quantity) {
this.order = order;
this.productCode = productCode;
this.productName = productName;
this.productModel = productModel;
this.unit = unit;
this.quantity = quantity;
this.productionStatus = "未生产";
}
// 带价格的构造函数
public OrderProduct(SalesOrder order, String productCode, String productName, String productModel, String unit, Integer quantity, BigDecimal unitPrice) {
this(order, productCode, productName, productModel, unit, quantity);
this.unitPrice = unitPrice;
this.totalPrice = unitPrice != null && quantity != null ? unitPrice.multiply(new BigDecimal(quantity)) : null;
}
// Getters and Setters
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public SalesOrder getOrder() {
return order;
}
public void setOrder(SalesOrder order) {
this.order = order;
}
public String getProductCode() {
return productCode;
}
public void setProductCode(String productCode) {
this.productCode = productCode;
}
public String getProductName() {
return productName;
}
public void setProductName(String productName) {
this.productName = productName;
}
public String getProductModel() {
return productModel;
}
public void setProductModel(String productModel) {
this.productModel = productModel;
}
public String getUnit() {
return unit;
}
public void setUnit(String unit) {
this.unit = unit;
}
public Integer getQuantity() {
return quantity;
}
public void setQuantity(Integer quantity) {
this.quantity = quantity;
// 更新总价
if (this.unitPrice != null && quantity != null) {
this.totalPrice = this.unitPrice.multiply(new BigDecimal(quantity));
}
}
public BigDecimal getUnitPrice() {
return unitPrice;
}
public void setUnitPrice(BigDecimal unitPrice) {
this.unitPrice = unitPrice;
// 更新总价
if (unitPrice != null && this.quantity != null) {
this.totalPrice = unitPrice.multiply(new BigDecimal(this.quantity));
}
}
public BigDecimal getTotalPrice() {
return totalPrice;
}
public void setTotalPrice(BigDecimal totalPrice) {
this.totalPrice = totalPrice;
}
public String getRemarks() {
return remarks;
}
public void setRemarks(String remarks) {
this.remarks = remarks;
}
public String getProductionStatus() {
return productionStatus;
}
public void setProductionStatus(String productionStatus) {
this.productionStatus = productionStatus;
}
@Override
public String toString() {
return "OrderProduct{" +
"id=" + id +
", productCode='" + productCode + ''' +
", productName='" + productName + ''' +
", productModel='" + productModel + ''' +
", quantity=" + quantity +
", unitPrice=" + unitPrice +
", totalPrice=" + totalPrice +
'}';
}
}package com.example.test.entity;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import java.time.LocalDateTime;
@Entity
@Table(name = "order_review")
public class OrderReview {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToOne
@JoinColumn(name = "order_id", nullable = false)
private SalesOrder order;
@Column(name = "review_type", nullable = false, length = 20)
private String reviewType; // 销售审核、生产审核、财务审核
@Column(name = "review_status", nullable = false, length = 20)
private String reviewStatus; // 待审核、已通过、已拒绝
@Column(name = "review_comments", length = 500)
private String reviewComments;
@ManyToOne
@JoinColumn(name = "reviewer_id")
private User reviewer;
@Column(name = "reviewer_name", length = 50)
private String reviewerName;
@Column(name = "review_time")
private LocalDateTime reviewTime;
@Column(name = "create_time")
private LocalDateTime createTime;
// 默认构造函数
public OrderReview() {
}
// 带基本参数的构造函数
public OrderReview(SalesOrder order, String reviewType) {
this.order = order;
this.reviewType = reviewType;
this.reviewStatus = "待审核";
this.createTime = LocalDateTime.now();
}
// 带审核人的构造函数
public OrderReview(SalesOrder order, String reviewType, User reviewer) {
this(order, reviewType);
this.reviewer = reviewer;
this.reviewerName = reviewer != null ? reviewer.getRealName() : null;
}
// Getters and Setters
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public SalesOrder getOrder() {
return order;
}
public void setOrder(SalesOrder order) {
this.order = order;
}
public String getReviewType() {
return reviewType;
}
public void setReviewType(String reviewType) {
this.reviewType = reviewType;
}
public String getReviewStatus() {
return reviewStatus;
}
public void setReviewStatus(String reviewStatus) {
this.reviewStatus = reviewStatus;
}
public String getReviewComments() {
return reviewComments;
}
public void setReviewComments(String reviewComments) {
this.reviewComments = reviewComments;
}
public User getReviewer() {
return reviewer;
}
public void setReviewer(User reviewer) {
this.reviewer = reviewer;
this.reviewerName = reviewer != null ? reviewer.getRealName() : null;
}
public String getReviewerName() {
return reviewerName;
}
public void setReviewerName(String reviewerName) {
this.reviewerName = reviewerName;
}
public LocalDateTime getReviewTime() {
return reviewTime;
}
public void setReviewTime(LocalDateTime reviewTime) {
this.reviewTime = reviewTime;
}
public LocalDateTime getCreateTime() {
return createTime;
}
public void setCreateTime(LocalDateTime createTime) {
this.createTime = createTime;
}
// 审核通过方法
public void approve(User reviewer, String comments) {
this.reviewer = reviewer;
this.reviewerName = reviewer != null ? reviewer.getRealName() : null;
this.reviewStatus = "已通过";
this.reviewComments = comments;
this.reviewTime = LocalDateTime.now();
}
// 审核拒绝方法
public void reject(User reviewer, String comments) {
this.reviewer = reviewer;
this.reviewerName = reviewer != null ? reviewer.getRealName() : null;
this.reviewStatus = "已拒绝";
this.reviewComments = comments;
this.reviewTime = LocalDateTime.now();
}
@Override
public String toString() {
return "OrderReview{" +
"id=" + id +
", reviewType='" + reviewType + ''' +
", reviewStatus='" + reviewStatus + ''' +
", reviewerName='" + reviewerName + ''' +
", reviewTime=" + reviewTime +
'}';
}
}package com.example.test.entity;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import java.math.BigDecimal;
import java.time.LocalDateTime;
@Entity
@Table(name = "product")
public class Product {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "product_code", nullable = false, unique = true, length = 50)
private String productCode;
@Column(name = "product_name", nullable = false, length = 100)
private String productName;
@Column(name = "product_model", length = 50)
private String productModel;
@Column(name = "product_type", length = 50)
private String productType;
@Column(name = "product_category", length = 50)
private String productCategory;
@Column(name = "unit", length = 20)
private String unit;
@Column(name = "standard_price", precision = 10, scale = 2)
private BigDecimal standardPrice;
@Column(name = "cost_price", precision = 10, scale = 2)
private BigDecimal costPrice;
@Column(name = "inventory_quantity")
private Integer inventoryQuantity;
@Column(name = "min_inventory")
private Integer minInventory;
@Column(name = "max_inventory")
private Integer maxInventory;
@Column(name = "production_cycle")
private Integer productionCycle; // 生产周期(天)
@Column(name = "product_status", length = 20)
private String productStatus; // 正常、停产、缺货
@Column(name = "description", length = 500)
private String description;
@Column(name = "create_time")
private LocalDateTime createTime;
@Column(name = "update_time")
private LocalDateTime updateTime;
@Column(name = "created_by")
private Long createdBy;
@Column(name = "updated_by")
private Long updatedBy;
// 默认构造函数
public Product() {
}
// 带基本参数的构造函数
public Product(String productCode, String productName, String productModel, String unit) {
this.productCode = productCode;
this.productName = productName;
this.productModel = productModel;
this.unit = unit;
this.inventoryQuantity = 0;
this.productStatus = "正常";
this.createTime = LocalDateTime.now();
this.updateTime = LocalDateTime.now();
}
// Getters and Setters
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getProductCode() {
return productCode;
}
public void setProductCode(String productCode) {
this.productCode = productCode;
}
public String getProductName() {
return productName;
}
public void setProductName(String productName) {
this.productName = productName;
}
public String getProductModel() {
return productModel;
}
public void setProductModel(String productModel) {
this.productModel = productModel;
}
public String getProductType() {
return productType;
}
public void setProductType(String productType) {
this.productType = productType;
}
public String getProductCategory() {
return productCategory;
}
public void setProductCategory(String productCategory) {
this.productCategory = productCategory;
}
public String getUnit() {
return unit;
}
public void setUnit(String unit) {
this.unit = unit;
}
public BigDecimal getStandardPrice() {
return standardPrice;
}
public void setStandardPrice(BigDecimal standardPrice) {
this.standardPrice = standardPrice;
}
public BigDecimal getCostPrice() {
return costPrice;
}
public void setCostPrice(BigDecimal costPrice) {
this.costPrice = costPrice;
}
public Integer getInventoryQuantity() {
return inventoryQuantity;
}
public void setInventoryQuantity(Integer inventoryQuantity) {
this.inventoryQuantity = inventoryQuantity;
}
public Integer getMinInventory() {
return minInventory;
}
public void setMinInventory(Integer minInventory) {
this.minInventory = minInventory;
}
public Integer getMaxInventory() {
return maxInventory;
}
public void setMaxInventory(Integer maxInventory) {
this.maxInventory = maxInventory;
}
public Integer getProductionCycle() {
return productionCycle;
}
public void setProductionCycle(Integer productionCycle) {
this.productionCycle = productionCycle;
}
public String getProductStatus() {
return productStatus;
}
public void setProductStatus(String productStatus) {
this.productStatus = productStatus;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public LocalDateTime getCreateTime() {
return createTime;
}
public void setCreateTime(LocalDateTime createTime) {
this.createTime = createTime;
}
public LocalDateTime getUpdateTime() {
return updateTime;
}
public void setUpdateTime(LocalDateTime updateTime) {
this.updateTime = updateTime;
}
public Long getCreatedBy() {
return createdBy;
}
public void setCreatedBy(Long createdBy) {
this.createdBy = createdBy;
}
public Long getUpdatedBy() {
return updatedBy;
}
public void setUpdatedBy(Long updatedBy) {
this.updatedBy = updatedBy;
}
@Override
public String toString() {
return "Product{" +
"id=" + id +
", productCode='" + productCode + ''' +
", productName='" + productName + ''' +
", productModel='" + productModel + ''' +
", inventoryQuantity=" + inventoryQuantity +
", productStatus='" + productStatus + ''' +
'}';
}
}package com.example.test.entity;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
@Entity
@Table(name = "product_cycle")
public class ProductCycle {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToOne
@JoinColumn(name = "product_id")
private Product product;
@Column(name = "product_code", nullable = false, length = 50)
private String productCode;
@Column(name = "product_name", length = 100)
private String productName;
@Column(name = "product_type", length = 50)
private String productType; // 产品类型:A、B、C等
@Column(name = "design_cycle")
private Integer designCycle; // 设计周期(天)
@Column(name = "material_preparation_cycle")
private Integer materialPreparationCycle; // 原材料准备周期(天)
@Column(name = "production_cycle")
private Integer productionCycle; // 生产周期(天)
@Column(name = "quality_inspection_cycle")
private Integer qualityInspectionCycle; // 质量检验周期(天)
@Column(name = "packaging_cycle")
private Integer packagingCycle; // 包装周期(天)
@Column(name = "total_cycle")
private Integer totalCycle; // 总周期(天)
// 默认构造函数
public ProductCycle() {
}
// 带基本参数的构造函数
public ProductCycle(Product product, String productType) {
this.product = product;
if (product != null) {
this.productCode = product.getProductCode();
this.productName = product.getProductName();
}
this.productType = productType;
}
// 带完整周期参数的构造函数
public ProductCycle(Product product, String productType, Integer designCycle, Integer materialPreparationCycle,
Integer productionCycle, Integer qualityInspectionCycle, Integer packagingCycle) {
this(product, productType);
this.designCycle = designCycle;
this.materialPreparationCycle = materialPreparationCycle;
this.productionCycle = productionCycle;
this.qualityInspectionCycle = qualityInspectionCycle;
this.packagingCycle = packagingCycle;
calculateTotalCycle();
}
// 计算总周期
private void calculateTotalCycle() {
this.totalCycle = (this.designCycle != null ? this.designCycle : 0) +
(this.materialPreparationCycle != null ? this.materialPreparationCycle : 0) +
(this.productionCycle != null ? this.productionCycle : 0) +
(this.qualityInspectionCycle != null ? this.qualityInspectionCycle : 0) +
(this.packagingCycle != null ? this.packagingCycle : 0);
}
// Getters and Setters
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Product getProduct() {
return product;
}
public void setProduct(Product product) {
this.product = product;
if (product != null) {
this.productCode = product.getProductCode();
this.productName = product.getProductName();
}
}
public String getProductCode() {
return productCode;
}
public void setProductCode(String productCode) {
this.productCode = productCode;
}
public String getProductName() {
return productName;
}
public void setProductName(String productName) {
this.productName = productName;
}
public String getProductType() {
return productType;
}
public void setProductType(String productType) {
this.productType = productType;
}
public Integer getDesignCycle() {
return designCycle;
}
public void setDesignCycle(Integer designCycle) {
this.designCycle = designCycle;
calculateTotalCycle();
}
public Integer getMaterialPreparationCycle() {
return materialPreparationCycle;
}
public void setMaterialPreparationCycle(Integer materialPreparationCycle) {
this.materialPreparationCycle = materialPreparationCycle;
calculateTotalCycle();
}
public Integer getProductionCycle() {
return productionCycle;
}
public void setProductionCycle(Integer productionCycle) {
this.productionCycle = productionCycle;
calculateTotalCycle();
}
public Integer getQualityInspectionCycle() {
return qualityInspectionCycle;
}
public void setQualityInspectionCycle(Integer qualityInspectionCycle) {
this.qualityInspectionCycle = qualityInspectionCycle;
calculateTotalCycle();
}
public Integer getPackagingCycle() {
return packagingCycle;
}
public void setPackagingCycle(Integer packagingCycle) {
this.packagingCycle = packagingCycle;
calculateTotalCycle();
}
public Integer getTotalCycle() {
return totalCycle;
}
public void setTotalCycle(Integer totalCycle) {
this.totalCycle = totalCycle;
}
@Override
public String toString() {
return "ProductCycle{" +
"id=" + id +
", productCode='" + productCode + ''' +
", productName='" + productName + ''' +
", productType='" + productType + ''' +
", totalCycle=" + totalCycle +
'}';
}
}/*
- Copyright (c) 2008, 2020 Oracle and/or its affiliates. All rights reserved.
- This program and the accompanying materials are made available under the
- terms of the Eclipse Public License v. 2.0 which is available at
- http://www.eclipse.org/legal/epl-2.0 ,
- or the Eclipse Distribution License v. 1.0 which is available at
- http://www.eclipse.org/org/documents/edl-v10.php.
- SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/
// Contributors:
// Linda DeMichiel - 2.1
// Linda DeMichiel - 2.0
package jakarta.persistence;
import java.lang.annotation.Target;
import java.lang.annotation.Retention;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
/**
-
Specifies the mapped column for a persistent property or field.
-
If no
Columnannotation is specified, the default values apply. -
-
Example 1:
-
@Column(name="DESC", nullable=false, length=512)
-
public String getDescription()
-
Example 2:
-
@Column(name="DESC",
-
columnDefinition="CLOB NOT NULL",
-
table="EMP_DETAIL")
-
@Lob
-
public String getDescription()
-
Example 3:
-
@Column(name="ORDER_COST", updatable=false, precision=12, scale=2)
-
public BigDecimal getCost()
-
@since 1.0
*/
@Target({METHOD, FIELD})
@Retention(RUNTIME)
public @interface Column {/**
- (Optional) The name of the column. Defaults to
- the property or field name.
*/
String name() default "";
/**
- (Optional) Whether the column is a unique key. This is a
- shortcut for the
UniqueConstraintannotation at the table - level and is useful for when the unique key constraint
- corresponds to only a single column. This constraint applies
- in addition to any constraint entailed by primary key mapping and
- to constraints specified at the table level.
*/
boolean unique() default false;
/**
- (Optional) Whether the database column is nullable.
*/
boolean nullable() default true;
/**
- (Optional) Whether the column is included in SQL INSERT
- statements generated by the persistence provider.
*/
boolean insertable() default true;
/**
- (Optional) Whether the column is included in SQL UPDATE
- statements generated by the persistence provider.
*/
boolean updatable() default true;
/**
- (Optional) The SQL fragment that is used when
- generating the DDL for the column.
-
Defaults to the generated SQL to create a
- column of the inferred type.
*/
String columnDefinition() default "";
/**
- (Optional) The name of the table that contains the column.
- If absent the column is assumed to be in the primary table.
*/
String table() default "";
/**
- (Optional) The column length. (Applies only if a
- string-valued column is used.)
*/
int length() default 255;
/**
- (Optional) The precision for a decimal (exact numeric)
- column. (Applies only if a decimal column is used.)
- Value must be set by developer if used when generating
- the DDL for the column.
*/
int precision() default 0;
/**
- (Optional) The scale for a decimal (exact numeric) column.
- (Applies only if a decimal column is used.)
*/
int scale() default 0;
}
package com.example.test.entity;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import java.time.LocalDateTime;
@Entity
@Table(name = "user")
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(nullable = false, length = 50, unique = true)
private String username;
@Column(nullable = false, length = 100)
private String password;
@Column(name = "real_name", length = 50)
private String realName;
@Column(length = 100)
private String email;
@Column(length = 20)
private String phone;
@Column(length = 50)
private String department;
@Column(length = 50)
private String position;
@Column(columnDefinition = "tinyint(1) default 1")
private Boolean status;
@Column(name = "create_time")
private LocalDateTime createTime;
@Column(name = "update_time")
private LocalDateTime updateTime;
@Column(name = "last_login_time")
private LocalDateTime lastLoginTime;
@Column(length = 20, columnDefinition = "varchar(20) default 'USER'")
private String role;
// 默认构造函数
public User() {
this.role = "USER";
}
// 带参数的构造函数
public User(String username, String password) {
this.username = username;
this.password = password;
this.status = true;
this.createTime = LocalDateTime.now();
this.updateTime = LocalDateTime.now();
this.role = "USER";
}
// 完整参数的构造函数
public User(String username, String password, String realName, String email, String phone,
String department, String position, Boolean status,
LocalDateTime createTime, LocalDateTime updateTime, LocalDateTime lastLoginTime) {
this.username = username;
this.password = password;
this.realName = realName;
this.email = email;
this.phone = phone;
this.department = department;
this.position = position;
this.status = status;
this.createTime = createTime;
this.updateTime = updateTime;
this.lastLoginTime = lastLoginTime;
this.role = "USER";
}
// 完整参数的构造函数(包含角色)
public User(String username, String password, String realName, String email, String phone,
String department, String position, Boolean status,
LocalDateTime createTime, LocalDateTime updateTime, LocalDateTime lastLoginTime,
String role) {
this.username = username;
this.password = password;
this.realName = realName;
this.email = email;
this.phone = phone;
this.department = department;
this.position = position;
this.status = status;
this.createTime = createTime;
this.updateTime = updateTime;
this.lastLoginTime = lastLoginTime;
this.role = role;
}
// Getters and Setters
public Long getId() {
return id;
}
public void setId(Long 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 getRealName() {
return realName;
}
public void setRealName(String realName) {
this.realName = realName;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getDepartment() {
return department;
}
public void setDepartment(String department) {
this.department = department;
}
public String getPosition() {
return position;
}
public void setPosition(String position) {
this.position = position;
}
public Boolean getStatus() {
return status;
}
public void setStatus(Boolean status) {
this.status = status;
}
public LocalDateTime getCreateTime() {
return createTime;
}
public void setCreateTime(LocalDateTime createTime) {
this.createTime = createTime;
}
public LocalDateTime getUpdateTime() {
return updateTime;
}
public void setUpdateTime(LocalDateTime updateTime) {
this.updateTime = updateTime;
}
public LocalDateTime getLastLoginTime() {
return lastLoginTime;
}
public void setLastLoginTime(LocalDateTime lastLoginTime) {
this.lastLoginTime = lastLoginTime;
}
public String getRole() {
return role;
}
public void setRole(String role) {
this.role = role;
}
// 判断是否为管理员
public boolean isAdmin() {
return "ADMIN".equals(this.role);
}
@Override
public String toString() {
return "User{" +
"id=" + id +
", username='" + username + ''' +
", password='" + password + ''' +
", realName='" + realName + ''' +
", email='" + email + ''' +
", phone='" + phone + ''' +
", department='" + department + ''' +
", position='" + position + ''' +
", status=" + status +
", createTime=" + createTime +
", updateTime=" + updateTime +
", lastLoginTime=" + lastLoginTime +
", role='" + role + ''' +
'}';
}
}package com.example.test.repository;
import com.example.test.entity.Product;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface ProductRepository extends JpaRepository<Product, Long> {
// 可以添加自定义查询方法
}package com.example.test.repository;
import com.example.test.entity.SalesOrder;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface SalesOrderRepository extends JpaRepository<SalesOrder, Long> {
// 可以添加自定义查询方法
}package com.example.test.repository;
import com.example.test.entity.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.time.LocalDateTime;
import java.util.List;
@Repository
public interface UserRepository extends JpaRepository<User, Long> {
// 根据用户名查找用户
User findByUsername(String username);
// 根据邮箱查找用户
User findByEmail(String email);
// 根据电话查找用户
User findByPhone(String phone);
// 根据部门查找用户列表
List
// 根据职位查找用户列表
List
// 根据状态查找用户列表
List
// 根据真实姓名模糊查询
List
// 查找指定时间之后创建的用户
List
// 查找指定时间之后登录的用户
List
// 自定义查询 - 根据部门和职位查找用户
@Query("SELECT u FROM User u WHERE u.department = :department AND u.position = :position")
List
// 根据角色查找用户列表
List
// 查找所有管理员
@Query("SELECT u FROM User u WHERE u.role = 'ADMIN'")
List
}package com.example.test.service;
import com.example.test.entity.*;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
import jakarta.persistence.Query;
import java.util.List;
/**
-
管理员服务类,提供对所有实体的通用操作
*/
@Service
public class AdminService {@PersistenceContext
private EntityManager entityManager;/**
- 获取所有实体记录
*/
publicList findAll(Class entityClass) {
return entityManager.createQuery("FROM " + entityClass.getSimpleName(), entityClass).getResultList();
}
/**
- 根据ID查找实体
*/
publicT findById(Class entityClass, Long id) {
return entityManager.find(entityClass, id);
}
/**
- 保存实体
*/
@Transactional
publicT save(T entity) {
if (entity == null) {
return null;
}
return entityManager.merge(entity);
}
/**
- 删除实体
*/
@Transactional
publicvoid delete(Class entityClass, Long id) {
T entity = findById(entityClass, id);
if (entity != null) {
entityManager.remove(entity);
}
}
/**
- 执行自定义查询
*/
publicList executeQuery(String jpql, Class resultClass) {
return entityManager.createQuery(jpql, resultClass).getResultList();
}
/**
- 执行自定义更新操作
*/
@Transactional
public int executeUpdate(String jpql) {
Query query = entityManager.createQuery(jpql);
return query.executeUpdate();
}
/**
- 根据实体名称获取对应的类
*/
public Class<?> getEntityClassByName(String entityName) {
try {
switch (entityName.toLowerCase()) {
case "user":
return User.class;
case "salesorder":
return SalesOrder.class;
case "orderproduct":
return OrderProduct.class;
case "missingproduct":
return MissingProduct.class;
case "product":
return Product.class;
case "productcycle":
return ProductCycle.class;
case "orderreview":
return OrderReview.class;
case "orderchange":
return OrderChange.class;
case "forecastplan":
return ForecastPlan.class;
case "deliveryorder":
return DeliveryOrder.class;
case "contactform":
return ContactForm.class;
case "deliverystatistics":
return DeliveryStatistics.class;
default:
return null;
}
} catch (Exception e) {
return null;
}
}
}package com.example.test.service;
- 获取所有实体记录
import com.example.test.entity.User;
import com.example.test.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;
@Service
public class UserService {
private final UserRepository userRepository;
@Autowired
public UserService(UserRepository userRepository) {
this.userRepository = userRepository;
}
// 创建用户
@Transactional
public User createUser(User user) {
// 设置默认值
if (user.getStatus() == null) {
user.setStatus(true);
}
if (user.getCreateTime() == null) {
user.setCreateTime(LocalDateTime.now());
}
if (user.getUpdateTime() == null) {
user.setUpdateTime(LocalDateTime.now());
}
if (user.getRole() == null) {
user.setRole("USER");
}
return userRepository.save(user);
}
// 创建管理员
@Transactional
public User createAdmin(User user) {
user.setRole("ADMIN");
return createUser(user);
}
// 更新用户
@Transactional
public User updateUser(User user) {
user.setUpdateTime(LocalDateTime.now());
return userRepository.save(user);
}
// 保存用户(创建或更新)
@Transactional
public User saveUser(User user) {
if (user.getId() == null) {
return createUser(user);
} else {
return updateUser(user);
}
}
// 根据ID查找用户
public Optional
return userRepository.findById(id);
}
// 查找所有用户
public List
return userRepository.findAll();
}
// 根据用户名查找用户
public User findUserByUsername(String username) {
return userRepository.findByUsername(username);
}
// 根据邮箱查找用户
public User findUserByEmail(String email) {
return userRepository.findByEmail(email);
}
// 根据电话查找用户
public User findUserByPhone(String phone) {
return userRepository.findByPhone(phone);
}
// 根据部门查找用户列表
public List
return userRepository.findByDepartment(department);
}
// 根据职位查找用户列表
public List
return userRepository.findByPosition(position);
}
// 根据部门和职位查找用户列表
public List
return userRepository.findByDepartmentAndPosition(department, position);
}
// 根据状态查找用户列表
public List
return userRepository.findByStatus(status);
}
// 根据角色查找用户列表
public List
return userRepository.findByRole(role);
}
// 查找所有管理员
public List
return userRepository.findAllAdmins();
}
// 根据真实姓名模糊查询
public List
return userRepository.findByRealNameContaining(realName);
}
// 查找指定时间之后创建的用户
public List
return userRepository.findByCreateTimeAfter(createTime);
}
// 查找指定时间之后登录的用户
public List
return userRepository.findByLastLoginTimeAfter(lastLoginTime);
}
// 用户登录
@Transactional
public User login(String username, String password) {
User user = userRepository.findByUsername(username);
if (user != null && password.equals(user.getPassword())) {
// 更新最后登录时间
user.setLastLoginTime(LocalDateTime.now());
return userRepository.save(user);
}
return null;
}
// 启用用户
@Transactional
public User enableUser(Long id) {
Optional
if (optionalUser.isPresent()) {
User user = optionalUser.get();
user.setStatus(true);
user.setUpdateTime(LocalDateTime.now());
return userRepository.save(user);
}
return null;
}
// 禁用用户
@Transactional
public User disableUser(Long id) {
Optional
if (optionalUser.isPresent()) {
User user = optionalUser.get();
user.setStatus(false);
user.setUpdateTime(LocalDateTime.now());
return userRepository.save(user);
}
return null;
}
// 设置用户为管理员
@Transactional
public User setUserAsAdmin(Long id) {
Optional
if (optionalUser.isPresent()) {
User user = optionalUser.get();
user.setRole("ADMIN");
user.setUpdateTime(LocalDateTime.now());
return userRepository.save(user);
}
return null;
}
// 取消用户的管理员权限
@Transactional
public User removeAdminRole(Long id) {
Optional
if (optionalUser.isPresent()) {
User user = optionalUser.get();
user.setRole("USER");
user.setUpdateTime(LocalDateTime.now());
return userRepository.save(user);
}
return null;
}
// 删除用户
@Transactional
public void deleteUser(Long id) {
userRepository.deleteById(id);
}
}
package com.example.test;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class TestApplication {
public static void main(String[] args) {
SpringApplication.run(TestApplication.class, args);
}
}
管理员仪表盘
用户总数
加载中...
订单总数
加载中...
产品总数
加载中...
待审核订单
加载中...
欢迎,管理员!
这是销售订单管理系统的管理员控制面板。您可以在这里管理系统中的所有数据。
请从左侧菜单选择要管理的数据类型。
用户管理
| ID | 用户名 | 姓名 | 邮箱 | 电话 | 部门 | 职位 | 角色 | 状态 | 创建时间 | 最后登录 | 操作 |
|---|
用户管理系统
用户总数
订单总数
产品总数
评审总数
用户管理
500
Internal Server Error
错误详情
时间: 2023-01-01 00:00:00
路径: /error
异常: Exception
堆栈跟踪:
Stack trace
销售订单管理系统
用户名或密码错误,请重试
您已成功退出登录
错误信息
成功信息
© 2023-2024
MySQLæ°æ®åºè¿æ¥é ç½®
spring.datasource.url=jdbc:mysql://localhost:3306/test?useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true
spring.datasource.username=root
spring.datasource.password=wcd20050614
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
JPAé ç½®
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect
é误å¤çé ç½®
server.error.include-message=always
server.error.include-binding-errors=always
server.error.include-stacktrace=never
server.error.include-exception=true
server.error.whitelabel.enabled=false`

浙公网安备 33010602011771号