This commit is contained in:
2026-01-13 15:43:14 +08:00
commit 444515d18c
57 changed files with 2373 additions and 0 deletions

View File

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

View File

@@ -0,0 +1,20 @@
package com.backend.webbackend.Controller;
import com.backend.webbackend.Service.courseService;
import com.backend.webbackend.Vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("course")
public class CourseController {
@Autowired
private courseService courseService;
@GetMapping("getAll")
public ResultVo getAllCourses() {
return ResultVo.Success("",courseService.getAllCourseInfo());
}
}

View File

@@ -0,0 +1,43 @@
package com.backend.webbackend.Controller;
import com.backend.webbackend.Service.userService;
import com.backend.webbackend.Vo.ResultVo;
import com.backend.webbackend.domain.User;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("user")
public class userController {
@Autowired
userService userService;
//返回所有部门信息
@GetMapping("dept")
public ResultVo getAllDept(){
return ResultVo.Success("",userService.getAlldept());
}
//用户注册
@PostMapping("register")
public ResultVo register(@RequestBody User user){
if(userService.register(user)){
return ResultVo.Success("","注册成功");
}
else {
return ResultVo.Error("","注册失败");
}
}
@PostMapping("login")
public ResultVo login(@RequestBody User user) {
if(!userService.login(user.getUsername(),user.getPassword())){
return ResultVo.Error("","用户名或密码错误");
}
return ResultVo.Success("","登陆成功");
}
}

View File

@@ -0,0 +1,18 @@
package com.backend.webbackend.Exception;
import com.backend.webbackend.Vo.ResultVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
@Slf4j
@ControllerAdvice//主要作用:统一异常处理,全局数据绑定:通过InitBinder为所有控制器添加预定义的数据绑定规则,全局模型属性,通过ModelAttribute注解为所有控制器的模型添加公共属性
public class GlobalExceptionHandler {
@ExceptionHandler(Exception.class)//异常捕获,当与ControllerAdvice注解一起使用时,可以捕获所有控制器抛出的异常,并统一处理
@ResponseBody//返回数据
public ResultVo error(Exception e){
log.error("Unhandled exception", e);
return ResultVo.Error("",e.getMessage());
}
}

View File

@@ -0,0 +1,23 @@
package com.backend.webbackend.Service.Impl;
import com.backend.webbackend.domain.Course;
import com.backend.webbackend.mapper.CourseMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class courseServiceImpl implements com.backend.webbackend.Service.courseService {
@Autowired
CourseMapper courseMapper;
@Override
public List<Course> getAllCourseInfo() {
// List<Course> courses = courseMapper.selectAllCourses();
// String path = courses.get(0).getCourseIco().trim()+"/"+courses.get(0).getCourseName().trim();
// System.out.println("path:"+path);
return courseMapper.selectAllCourses();
}
}

View File

@@ -0,0 +1,80 @@
package com.backend.webbackend.Service.Impl;
import com.backend.webbackend.Service.userService;
import com.backend.webbackend.Tools.Tools;
import com.backend.webbackend.domain.Dept;
import com.backend.webbackend.domain.User;
import com.backend.webbackend.mapper.DeptMapper;
import com.backend.webbackend.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
@Service
public class userServiceImpl implements userService {
@Autowired
private UserMapper userMapper;
@Autowired
private DeptMapper deptMapper;
@Autowired
private Tools tools;
//注册用户实现
@Override
public boolean register(User user) {
//检查用户名唯一性
String userName = user.getUsername()==null?null:user.getUsername().trim();
user.setUsername(userName);
if(!tools.checkUsernameUnique(userName)){
throw new IllegalArgumentException("用户名已存在");
}
//校验手机号完整性
if(!tools.checkPhoneUnique(user.getPhone())){
throw new IllegalArgumentException("手机号格式不合法");
}
//密码加密处理,内部已有异常处理
String encryptedPassword = tools.encryptPassword(user.getPassword());
user.setPassword(encryptedPassword);
//获取部门id
Dept dept = deptMapper.selectIdByName(user.getDeptName());
if(dept == null){
throw new IllegalArgumentException("部门不存在");
}
user.setDeptId(dept.getId());
//设置创建和登陆时间
user.setCreateTime(new Date());
user.setLastLoginTime(new Date());
//默认用户状态为正常
user.setStatus(1);
user.setRole(2);
return userMapper.insert(user) == 1;
}
//用户登录实现
@Override
public boolean login(String username, String password) {
User user = userMapper.selectByUsername(username);
if(user == null){
throw new IllegalArgumentException("用户不存在");
}
//验证密码
if(!tools.matchesPassword(password, user.getPassword())){
throw new IllegalArgumentException("密码错误");
}
//更新最后登录时间
user.setLastLoginTime(new Date());
return userMapper.updateById(user)==1;
}
@Override
public List<Dept> getAlldept() {
return deptMapper.selectAllDept();
}
}

View File

@@ -0,0 +1,11 @@
package com.backend.webbackend.Service;
import com.backend.webbackend.domain.Course;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public interface courseService {
List<Course> getAllCourseInfo();
}

View File

@@ -0,0 +1,16 @@
package com.backend.webbackend.Service;
import com.backend.webbackend.domain.Dept;
import com.backend.webbackend.domain.User;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public interface userService {
//注册
boolean register(User user);
boolean login(String username, String password);
List<Dept> getAlldept();
}

View File

@@ -0,0 +1,52 @@
package com.backend.webbackend.Tools;
import com.backend.webbackend.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;
import java.util.regex.Pattern;
@Service
public class Tools {
private static final Pattern CN_MOBILE_PATTERN = Pattern.compile("^1[3-9]\\d{9}$");
// 定义编码器,解决 PASSWORD_ENCODER 无法解析
private static final BCryptPasswordEncoder PASSWORD_ENCODER = new BCryptPasswordEncoder();
@Autowired
private final UserMapper userMapper;
public Tools(UserMapper userMapper) {
this.userMapper = userMapper;
}
//校验用户名唯一性
public boolean checkUsernameUnique(String username) {
return userMapper.countByUsername(username)==0;
}
//校验手机号格式合法性
public boolean checkPhoneUnique(String phone) {
if (phone == null) {
return false;
}
String p = phone.trim();
return CN_MOBILE_PATTERN.matcher(p).matches();
}
// 用户名密码加密处理BCrypt加盐慢哈希
public String encryptPassword(String password) {
if (password == null || password.trim().isEmpty()) {
throw new IllegalArgumentException("密码不能为空");
}
return PASSWORD_ENCODER.encode(password);
}
// 校验明文密码是否匹配已加密密码
public boolean matchesPassword(String rawPassword, String encodedPassword) {
if (rawPassword == null || encodedPassword == null) {
return false;
}
return PASSWORD_ENCODER.matches(rawPassword, encodedPassword);
}
}

View File

@@ -0,0 +1,22 @@
package com.backend.webbackend.Vo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data //为所有字段自动生成getter、setter、toString、equals和hashCode方法
@AllArgsConstructor //生成一个包含所有字段的构造函数
@NoArgsConstructor// 生成一个无参构造函数
public class ResultVo {
private Integer Code; //返回代码
private String msg; //返回消息
private Object data; //返回数据
static public ResultVo Success(String msg,Object data){
return new ResultVo(2000,msg,data);
}
static public ResultVo Error(String msg,Object data){return new ResultVo(5000,msg,data);}
}

View File

@@ -0,0 +1,23 @@
package com.backend.webbackend.domain;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
/**
* @TableName course
*/
@Data
public class Course {
private Long id;
private String courseName;
private String courseCode;
private String courseDesc;
private String courseCategory;
@JsonProperty("course_ico")
private String courseIco;
}

View File

@@ -0,0 +1,13 @@
package com.backend.webbackend.domain;
import lombok.Data;
/**
* @TableName course_type
*/
@Data
public class CourseType {
private Integer id;
private String typename;
}

View File

@@ -0,0 +1,15 @@
package com.backend.webbackend.domain;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
/**
* @TableName dept
*/
@Data
public class Dept {
private Long id;
@JsonProperty("dept_name")
private String deptName;
}

View File

@@ -0,0 +1,19 @@
package com.backend.webbackend.domain;
import lombok.Data;
/**
* @TableName device
*/
@Data
public class Device {
private Long id;
private String deviceCode;
private String deviceName;
private String deviceStatus;
private String model;
}

View File

@@ -0,0 +1,19 @@
package com.backend.webbackend.domain;
import lombok.Data;
/**
* @TableName exam_paper
*/
@Data
public class ExamPaper {
private Long id;
private String paperName;
private String paperCode;
private String paperDesc;
private Integer totalScore;
}

View File

@@ -0,0 +1,28 @@
package com.backend.webbackend.domain;
import java.util.Date;
import lombok.Data;
/**
* @TableName fault_event
*/
@Data
public class FaultEvent {
private Long id;
private String eventCode;
private Long deviceId;
private Long partId;
private Long faultItemId;
private Date occurTime;
private String phenomenonDesc;
private String reasonAnalysis;
private String processingMeasures;
}

View File

@@ -0,0 +1,26 @@
package com.backend.webbackend.domain;
import java.util.Date;
import lombok.Data;
/**
* @TableName fault_item
*/
@Data
public class FaultItem {
private Long id;
private String faultCode;
private String faultName;
private String faultDesc;
private Long deviceId;
private Long partId;
private Long creatorId;
private Date createTime;
}

View File

@@ -0,0 +1,17 @@
package com.backend.webbackend.domain;
import lombok.Data;
/**
* @TableName model_file
*/
@Data
public class ModelFile {
private Long id;
private Long partId;
private String fileName;
private String filePath;
}

View File

@@ -0,0 +1,19 @@
package com.backend.webbackend.domain;
import lombok.Data;
/**
* @TableName part
*/
@Data
public class Part {
private Long id;
private String partCode;
private String partName;
private Long deviceId;
private String partDesc;
}

View File

@@ -0,0 +1,19 @@
package com.backend.webbackend.domain;
import lombok.Data;
/**
* @TableName training_resource
*/
@Data
public class TrainingResource {
private Long id;
private String resourceName;
private String resourceType;
private String filePath;
private Long courseId;
}

View File

@@ -0,0 +1,31 @@
package com.backend.webbackend.domain;
import lombok.Data;
/**
* @TableName troubleshoot_node
*/
@Data
public class TroubleshootNode {
private Long id;
private Long faultItemId;
private Integer stepOrder;
private String stepName;
private String stepDesc;
private String checkItems;
private String measurementPoint;
private String judgeStandard;
private Long nextNodeId;
private String branchCondition;
private Integer isLeaf;
}

View File

@@ -0,0 +1,40 @@
package com.backend.webbackend.domain;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
/**
* @TableName user
*/
@Data
public class User {
private Long id;
private String username;
private String password;
@JsonProperty("real_name")
private String realName;
@JsonProperty("dept_id")
private Long deptId;
@JsonProperty("dept_name")
private String deptName;
private String phone;
private Integer role;
private Integer status;
@JsonProperty("create_time")
private Date createTime;
@JsonProperty("last_login_time")
private Date lastLoginTime;
}

View File

@@ -0,0 +1,17 @@
package com.backend.webbackend.domain;
import lombok.Data;
/**
* @TableName user_exam_score
*/
@Data
public class UserExamScore {
private Long id;
private Long userId;
private Long paperId;
private Integer score;
}

View File

@@ -0,0 +1,19 @@
package com.backend.webbackend.domain;
import lombok.Data;
/**
* @TableName user_learning_record
*/
@Data
public class UserLearningRecord {
private Long id;
private Long userId;
private Long courseId;
private Long resourceId;
private String status;
}

View File

@@ -0,0 +1,29 @@
package com.backend.webbackend.mapper;
import com.backend.webbackend.domain.Course;
import java.util.List;
/**
* @author Quella
* @description 针对表【course(课程表)】的数据库操作Mapper
* @createDate 2026-01-12 16:27:05
* @Entity generator.domain.Course
*/
public interface CourseMapper {
int deleteByPrimaryKey(Long id);
int insert(Course record);
int insertSelective(Course record);
Course selectByPrimaryKey(Long id);
List<Course> selectAllCourses();
int updateByPrimaryKeySelective(Course record);
int updateByPrimaryKey(Course record);
}

View File

@@ -0,0 +1,25 @@
package com.backend.webbackend.mapper;
import com.backend.webbackend.domain.CourseType;
/**
* @author Quella
* @description 针对表【course_type】的数据库操作Mapper
* @createDate 2026-01-13 15:15:07
* @Entity com.backend.webbackend.domain.CourseType
*/
public interface CourseTypeMapper {
int deleteByPrimaryKey(Long id);
int insert(CourseType record);
int insertSelective(CourseType record);
CourseType selectByPrimaryKey(Long id);
int updateByPrimaryKeySelective(CourseType record);
int updateByPrimaryKey(CourseType record);
}

View File

@@ -0,0 +1,30 @@
package com.backend.webbackend.mapper;
import com.backend.webbackend.domain.Dept;
import java.util.List;
/**
* @author Quella
* @description 针对表【dept(部门表)】的数据库操作Mapper
* @createDate 2026-01-12 16:27:05
* @Entity generator.domain.Dept
*/
public interface DeptMapper {
int deleteByPrimaryKey(Long id);
int insert(Dept record);
int insertSelective(Dept record);
Dept selectByPrimaryKey(Long id);
int updateByPrimaryKeySelective(Dept record);
int updateByPrimaryKey(Dept record);
List<Dept> selectAllDept();
Dept selectIdByName(String name);
}

View File

@@ -0,0 +1,25 @@
package com.backend.webbackend.mapper;
import com.backend.webbackend.domain.Device;
/**
* @author Quella
* @description 针对表【device(设备表)】的数据库操作Mapper
* @createDate 2026-01-12 16:27:05
* @Entity generator.domain.Device
*/
public interface DeviceMapper {
int deleteByPrimaryKey(Long id);
int insert(Device record);
int insertSelective(Device record);
Device selectByPrimaryKey(Long id);
int updateByPrimaryKeySelective(Device record);
int updateByPrimaryKey(Device record);
}

View File

@@ -0,0 +1,25 @@
package com.backend.webbackend.mapper;
import com.backend.webbackend.domain.ExamPaper;
/**
* @author Quella
* @description 针对表【exam_paper(试卷表)】的数据库操作Mapper
* @createDate 2026-01-12 16:27:05
* @Entity generator.domain.ExamPaper
*/
public interface ExamPaperMapper {
int deleteByPrimaryKey(Long id);
int insert(ExamPaper record);
int insertSelective(ExamPaper record);
ExamPaper selectByPrimaryKey(Long id);
int updateByPrimaryKeySelective(ExamPaper record);
int updateByPrimaryKey(ExamPaper record);
}

View File

@@ -0,0 +1,25 @@
package com.backend.webbackend.mapper;
import com.backend.webbackend.domain.FaultEvent;
/**
* @author Quella
* @description 针对表【fault_event(故障事件表)】的数据库操作Mapper
* @createDate 2026-01-12 16:27:05
* @Entity generator.domain.FaultEvent
*/
public interface FaultEventMapper {
int deleteByPrimaryKey(Long id);
int insert(FaultEvent record);
int insertSelective(FaultEvent record);
FaultEvent selectByPrimaryKey(Long id);
int updateByPrimaryKeySelective(FaultEvent record);
int updateByPrimaryKey(FaultEvent record);
}

View File

@@ -0,0 +1,25 @@
package com.backend.webbackend.mapper;
import com.backend.webbackend.domain.FaultItem;
/**
* @author Quella
* @description 针对表【fault_item(故障条目表)】的数据库操作Mapper
* @createDate 2026-01-12 16:27:05
* @Entity generator.domain.FaultItem
*/
public interface FaultItemMapper {
int deleteByPrimaryKey(Long id);
int insert(FaultItem record);
int insertSelective(FaultItem record);
FaultItem selectByPrimaryKey(Long id);
int updateByPrimaryKeySelective(FaultItem record);
int updateByPrimaryKey(FaultItem record);
}

View File

@@ -0,0 +1,25 @@
package com.backend.webbackend.mapper;
import com.backend.webbackend.domain.ModelFile;
/**
* @author Quella
* @description 针对表【model_file(模型文件表)】的数据库操作Mapper
* @createDate 2026-01-12 16:27:05
* @Entity generator.domain.ModelFile
*/
public interface ModelFileMapper {
int deleteByPrimaryKey(Long id);
int insert(ModelFile record);
int insertSelective(ModelFile record);
ModelFile selectByPrimaryKey(Long id);
int updateByPrimaryKeySelective(ModelFile record);
int updateByPrimaryKey(ModelFile record);
}

View File

@@ -0,0 +1,25 @@
package com.backend.webbackend.mapper;
import com.backend.webbackend.domain.Part;
/**
* @author Quella
* @description 针对表【part(部件表)】的数据库操作Mapper
* @createDate 2026-01-12 16:27:05
* @Entity generator.domain.Part
*/
public interface PartMapper {
int deleteByPrimaryKey(Long id);
int insert(Part record);
int insertSelective(Part record);
Part selectByPrimaryKey(Long id);
int updateByPrimaryKeySelective(Part record);
int updateByPrimaryKey(Part record);
}

View File

@@ -0,0 +1,25 @@
package com.backend.webbackend.mapper;
import com.backend.webbackend.domain.TrainingResource;
/**
* @author Quella
* @description 针对表【training_resource(培训资源表)】的数据库操作Mapper
* @createDate 2026-01-12 16:27:05
* @Entity generator.domain.TrainingResource
*/
public interface TrainingResourceMapper {
int deleteByPrimaryKey(Long id);
int insert(TrainingResource record);
int insertSelective(TrainingResource record);
TrainingResource selectByPrimaryKey(Long id);
int updateByPrimaryKeySelective(TrainingResource record);
int updateByPrimaryKey(TrainingResource record);
}

View File

@@ -0,0 +1,25 @@
package com.backend.webbackend.mapper;
import com.backend.webbackend.domain.TroubleshootNode;
/**
* @author Quella
* @description 针对表【troubleshoot_node(排故流程节点表)】的数据库操作Mapper
* @createDate 2026-01-12 16:27:05
* @Entity generator.domain.TroubleshootNode
*/
public interface TroubleshootNodeMapper {
int deleteByPrimaryKey(Long id);
int insert(TroubleshootNode record);
int insertSelective(TroubleshootNode record);
TroubleshootNode selectByPrimaryKey(Long id);
int updateByPrimaryKeySelective(TroubleshootNode record);
int updateByPrimaryKey(TroubleshootNode record);
}

View File

@@ -0,0 +1,25 @@
package com.backend.webbackend.mapper;
import com.backend.webbackend.domain.UserExamScore;
/**
* @author Quella
* @description 针对表【user_exam_score(用户考试成绩表)】的数据库操作Mapper
* @createDate 2026-01-12 16:27:05
* @Entity generator.domain.UserExamScore
*/
public interface UserExamScoreMapper {
int deleteByPrimaryKey(Long id);
int insert(UserExamScore record);
int insertSelective(UserExamScore record);
UserExamScore selectByPrimaryKey(Long id);
int updateByPrimaryKeySelective(UserExamScore record);
int updateByPrimaryKey(UserExamScore record);
}

View File

@@ -0,0 +1,25 @@
package com.backend.webbackend.mapper;
import com.backend.webbackend.domain.UserLearningRecord;
/**
* @author Quella
* @description 针对表【user_learning_record(用户学习记录表)】的数据库操作Mapper
* @createDate 2026-01-12 16:27:05
* @Entity generator.domain.UserLearningRecord
*/
public interface UserLearningRecordMapper {
int deleteByPrimaryKey(Long id);
int insert(UserLearningRecord record);
int insertSelective(UserLearningRecord record);
UserLearningRecord selectByPrimaryKey(Long id);
int updateByPrimaryKeySelective(UserLearningRecord record);
int updateByPrimaryKey(UserLearningRecord record);
}

View File

@@ -0,0 +1,31 @@
package com.backend.webbackend.mapper;
import com.backend.webbackend.domain.User;
import org.apache.ibatis.annotations.Param;
/**
* @author Quella
* @description 针对表【user(用户表)】的数据库操作Mapper
* @createDate 2026-01-12 16:27:05
* @Entity generator.domain.User
*/
public interface UserMapper {
int deleteByPrimaryKey(Long id);
int insert(User record);
int insertSelective(User record);
User selectByPrimaryKey(Long id);
User selectByUsername(@Param("username") String username);
int updateByPrimaryKeySelective(User record);
int updateByPrimaryKey(User record);
int countByUsername(@Param("username") String username);
int updateById(User user);
}