v1.0
This commit is contained in:
1 parent
619e5665e2
commit
b95c8e151f
8 files changed
+197
-19
No files matched your search
@@ -74,7 +74,8 @@ public class SecurityConfig {
|
|||||||
"http://localhost:3000", // 其他可能的端口
|
"http://localhost:3000", // 其他可能的端口
|
||||||
"https://charging.tianshu.cyou" , // 生产环境可能的地址
|
"https://charging.tianshu.cyou" , // 生产环境可能的地址
|
||||||
"https://charging.hong.email" ,
|
"https://charging.hong.email" ,
|
||||||
"https://www.hong.email" // 生产环境可能的地址
|
"https://www.hong.email", // 生产环境可能的地址
|
||||||
|
"http://192.168.1.35:3000" // 内网地址
|
||||||
));
|
));
|
||||||
|
|
||||||
// 允许的HTTP方法
|
// 允许的HTTP方法
|
||||||
|
|||||||
@@ -3,10 +3,14 @@ package com.tianze.www.controller;
|
|||||||
import com.tianze.www.service.UserService;
|
import com.tianze.www.service.UserService;
|
||||||
import com.tianze.www.util.JwtUtil;
|
import com.tianze.www.util.JwtUtil;
|
||||||
import com.tianze.www.dto.LoginResponse;
|
import com.tianze.www.dto.LoginResponse;
|
||||||
|
import com.tianze.www.dto.RepairResponse;
|
||||||
import com.tianze.www.dto.SearchRequest;
|
import com.tianze.www.dto.SearchRequest;
|
||||||
import com.tianze.www.dto.SearchResponse;
|
import com.tianze.www.dto.SearchResponse;
|
||||||
|
import com.tianze.www.dto.UpdateOilRequest;
|
||||||
|
import com.tianze.www.dto.UpdateRequest;
|
||||||
import com.tianze.www.dto.UserList;
|
import com.tianze.www.dto.UserList;
|
||||||
import com.tianze.www.entity.UserInfo;
|
import com.tianze.www.entity.UserInfo;
|
||||||
|
import com.tianze.www.dto.AddRepairRequest;
|
||||||
import com.tianze.www.dto.AddUserRequest;
|
import com.tianze.www.dto.AddUserRequest;
|
||||||
import com.tianze.www.dto.LoginRequest;
|
import com.tianze.www.dto.LoginRequest;
|
||||||
|
|
||||||
@@ -14,7 +18,9 @@ import java.util.List;
|
|||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PutMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
@@ -90,4 +96,48 @@ public class UserController {
|
|||||||
response.setTotal((int) totalCount);
|
response.setTotal((int) totalCount);
|
||||||
return ResponseEntity.ok(response);
|
return ResponseEntity.ok(response);
|
||||||
}
|
}
|
||||||
}
|
@GetMapping("/getUser") // @PostMapping注解表示该方法处理HTTP POST请求,路径为"/update"
|
||||||
|
public ResponseEntity<UserInfo> getUser(@RequestParam String plateNumber) {
|
||||||
|
// 这里可以调用UserService的方法获取用户列表
|
||||||
|
// 例如:List<UserInfo> users = userService.getAllUsers();
|
||||||
|
UserInfo userInfo = userService.getUserByPlateNumber(plateNumber);
|
||||||
|
if (userInfo == null) {
|
||||||
|
return ResponseEntity.status(202).build();
|
||||||
|
}
|
||||||
|
userInfo.setPassword(null); // 不返回密码字段
|
||||||
|
return ResponseEntity.ok(userInfo);
|
||||||
|
}
|
||||||
|
@PutMapping ("/updateUser") // @PutMapping注解表示该方法处理HTTP PUT请求,路径为"/update"
|
||||||
|
public ResponseEntity<String> updateUser(@RequestBody UpdateRequest updateRequest) {
|
||||||
|
// 这里可以调用UserService的更新方法进行用户信息更新
|
||||||
|
// 例如:userService.updateUser(userInfo);
|
||||||
|
if (!userService.updateUser(updateRequest)) {
|
||||||
|
return ResponseEntity.status(202).body("Failed to update user");
|
||||||
|
}
|
||||||
|
return ResponseEntity.ok("User updated successfully");
|
||||||
|
}
|
||||||
|
@PutMapping ("/updateUserOil") // @PutMapping注解表示该方法处理HTTP PUT请求,路径为"/update"
|
||||||
|
public ResponseEntity<String> updateUserOil(@RequestParam Long id, @RequestBody UpdateOilRequest updateOilRequest) {
|
||||||
|
// 这里可以调用UserService的更新方法进行用户油品信息更新
|
||||||
|
// 例如:userService.updateUserOil(userInfo);
|
||||||
|
if (!userService.updateUserOil(id, updateOilRequest)) {
|
||||||
|
return ResponseEntity.status(202).body("Failed to update user oil");
|
||||||
|
}
|
||||||
|
return ResponseEntity.ok("User oil updated successfully");
|
||||||
|
}
|
||||||
|
@PostMapping ("/addRepairRecord")
|
||||||
|
public ResponseEntity<String> addRepairRecord(@RequestBody AddRepairRequest addRepairRequest) {
|
||||||
|
// 这里可以调用UserService的方法添加维修记录
|
||||||
|
if (!userService.addRepairRecord(addRepairRequest)) {
|
||||||
|
return ResponseEntity.status(202).body("Failed to add repair record");
|
||||||
|
}
|
||||||
|
return ResponseEntity.ok("Repair record added successfully");
|
||||||
|
}
|
||||||
|
@GetMapping("/getRepairRecords")
|
||||||
|
public ResponseEntity<List<RepairResponse>> getRepairRecords(@RequestParam Long userId) {
|
||||||
|
// 这里可以调用UserService的方法获取维修记录列表
|
||||||
|
// 例如:List<String> repairRecords = userService.getRepairRecords(userId);
|
||||||
|
List<RepairResponse> repairRecords = userService.getRepairRecords(userId);
|
||||||
|
return ResponseEntity.ok(repairRecords);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package com.tianze.www.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class AddRepairRequest {
|
||||||
|
private Long id;
|
||||||
|
private String title;
|
||||||
|
private String description;
|
||||||
|
private String date;
|
||||||
|
private Integer price;
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package com.tianze.www.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class RepairResponse {
|
||||||
|
public RepairResponse() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public RepairResponse(Long id, String title, String description, String date, Integer price) {
|
||||||
|
this.id = id;
|
||||||
|
this.title = title;
|
||||||
|
this.description = description;
|
||||||
|
this.date = date;
|
||||||
|
this.price = price;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Long id;
|
||||||
|
private String title;
|
||||||
|
private String description;
|
||||||
|
private String date;
|
||||||
|
private Integer price;
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package com.tianze.www.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class UpdateOilRequest {
|
||||||
|
private String type;
|
||||||
|
private Integer duration;
|
||||||
|
private Integer kilometers;
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package com.tianze.www.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class UpdateRequest {
|
||||||
|
private Long id;
|
||||||
|
private String plateNumber;
|
||||||
|
private String status;
|
||||||
|
private String carModel;
|
||||||
|
private String carColor;
|
||||||
|
private Integer purchaseYear;
|
||||||
|
private String oilChangedAt;
|
||||||
|
private String oilType;
|
||||||
|
private String oilCycle;
|
||||||
|
private Integer oilDuration;
|
||||||
|
private String nextOilDate;
|
||||||
|
private String updatedAt;
|
||||||
|
}
|
||||||
@@ -1,13 +1,15 @@
|
|||||||
package com.tianze.www.mapper;
|
package com.tianze.www.mapper;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.tianze.www.dto.RepairResponse;
|
||||||
import com.tianze.www.entity.UserInfo;
|
import com.tianze.www.entity.UserInfo;
|
||||||
|
|
||||||
import org.apache.ibatis.annotations.Insert;
|
import org.apache.ibatis.annotations.Insert;
|
||||||
import org.apache.ibatis.annotations.Options;
|
import org.apache.ibatis.annotations.Options;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
import org.apache.ibatis.annotations.Select;
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface UserInfoMapper extends BaseMapper<UserInfo> {
|
public interface UserInfoMapper extends BaseMapper<UserInfo> {
|
||||||
@@ -27,7 +29,7 @@ public interface UserInfoMapper extends BaseMapper<UserInfo> {
|
|||||||
"</script>")
|
"</script>")
|
||||||
List<UserInfo> getUsers(@Param("keyword") String keyword,
|
List<UserInfo> getUsers(@Param("keyword") String keyword,
|
||||||
@Param("offset") int offset,
|
@Param("offset") int offset,
|
||||||
@Param("pageSize") int pageSize);
|
@Param("pageSize") int pageSize);// 返回用户列表
|
||||||
|
|
||||||
@Select("<script>" +
|
@Select("<script>" +
|
||||||
"SELECT COUNT(*) FROM customer_vehicle " +
|
"SELECT COUNT(*) FROM customer_vehicle " +
|
||||||
@@ -37,20 +39,11 @@ public interface UserInfoMapper extends BaseMapper<UserInfo> {
|
|||||||
" </if>" +
|
" </if>" +
|
||||||
"</where>" +
|
"</where>" +
|
||||||
"</script>")
|
"</script>")
|
||||||
long countUsers(@Param("keyword") String keyword);
|
long countUsers(@Param("keyword") String keyword);// 返回用户数量
|
||||||
|
|
||||||
@Select("SELECT * FROM customer_vehicle WHERE plate_number = #{plate_number} ORDER BY created_at DESC")
|
@Select("SELECT * FROM customer_vehicle WHERE plate_number = #{plate_number} ORDER BY created_at DESC")
|
||||||
UserInfo findByPlateNumber(@Param("plate_number") String plateNumber);
|
UserInfo findByPlateNumber(@Param("plate_number") String plateNumber);
|
||||||
|
|
||||||
@Select("SELECT * FROM customer_vehicle WHERE phone = #{phone} ORDER BY created_at DESC")
|
|
||||||
UserInfo findByPhone(@Param("phone") String phone);
|
|
||||||
|
|
||||||
@Select("SELECT COUNT(*) FROM customer_vehicle WHERE email = #{email}")
|
|
||||||
boolean existsByEmail(@Param("email") String email);
|
|
||||||
|
|
||||||
@Select("SELECT COUNT(*) FROM customer_vehicle WHERE phone = #{phone}")
|
|
||||||
boolean existsByPhone(@Param("phone") String phone);
|
|
||||||
|
|
||||||
@Insert("INSERT INTO customer_vehicle (" +
|
@Insert("INSERT INTO customer_vehicle (" +
|
||||||
"plate_number, password, role, status, " +
|
"plate_number, password, role, status, " +
|
||||||
"car_model, car_color, purchase_date, " +
|
"car_model, car_color, purchase_date, " +
|
||||||
@@ -60,8 +53,26 @@ public interface UserInfoMapper extends BaseMapper<UserInfo> {
|
|||||||
"#{carModel}, #{carColor}, #{purchaseDate}, " +
|
"#{carModel}, #{carColor}, #{purchaseDate}, " +
|
||||||
"#{oilType}, #{oilCycle}, #{lastOilDate}, #{nextOilDate}" +
|
"#{oilType}, #{oilCycle}, #{lastOilDate}, #{nextOilDate}" +
|
||||||
")")
|
")")
|
||||||
@Options(useGeneratedKeys = true, keyProperty = "id") // 将自增ID返回给实体类的id属性
|
@Options(useGeneratedKeys = true, keyProperty = "id")
|
||||||
int insertUser(UserInfo userInfo);
|
int insertUser(UserInfo userInfo);// 返回插入的行数
|
||||||
|
|
||||||
|
@Insert("INSERT INTO repair_record (vehicle_id, title, description, repair_date, price) " +
|
||||||
|
"VALUES (#{vehicleId}, #{title}, #{description}, #{repairDate}, #{price})")
|
||||||
|
int addRepairRecord(
|
||||||
|
@Param("vehicleId") Long vehicleId,
|
||||||
|
@Param("title") String title,
|
||||||
|
@Param("description") String description,
|
||||||
|
@Param("repairDate") LocalDate repairDate,
|
||||||
|
@Param("price") Integer price // 如果前端传 "680",用 String 接收 MyBatis 也能自动转成 DECIMAL
|
||||||
|
);
|
||||||
|
|
||||||
|
@Select("SELECT id, title, description, price, repair_date AS repairDate, " +
|
||||||
|
"warranty_months AS warrantyMonths, warranty_end_date AS warrantyEndDate, " +
|
||||||
|
"parts_manufacturer AS partsManufacturer " +
|
||||||
|
"FROM repair_record " +
|
||||||
|
"WHERE vehicle_id = #{userId} " +
|
||||||
|
"ORDER BY repair_date DESC")
|
||||||
|
List<RepairResponse> getRepairRecords(@Param("userId") Long userId);
|
||||||
/**
|
/**
|
||||||
* 方式2:注解SQL带条件
|
* 方式2:注解SQL带条件
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,13 +1,19 @@
|
|||||||
package com.tianze.www.service;
|
package com.tianze.www.service;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import com.tianze.www.dto.AddRepairRequest;
|
||||||
import com.tianze.www.dto.AddUserRequest;
|
import com.tianze.www.dto.AddUserRequest;
|
||||||
import com.tianze.www.dto.Jwt;
|
import com.tianze.www.dto.Jwt;
|
||||||
import com.tianze.www.dto.LoginRequest;
|
import com.tianze.www.dto.LoginRequest;
|
||||||
|
import com.tianze.www.dto.RepairResponse;
|
||||||
|
import com.tianze.www.dto.UpdateOilRequest;
|
||||||
|
import com.tianze.www.dto.UpdateRequest;
|
||||||
import com.tianze.www.entity.UserInfo;
|
import com.tianze.www.entity.UserInfo;
|
||||||
import com.tianze.www.mapper.UserInfoMapper;
|
import com.tianze.www.mapper.UserInfoMapper;
|
||||||
import com.tianze.www.util.JwtUtil;
|
import com.tianze.www.util.JwtUtil;
|
||||||
@@ -15,12 +21,13 @@ import com.tianze.www.util.PasswordUtil;
|
|||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class UserService {
|
public class UserService {
|
||||||
@Autowired
|
@Autowired
|
||||||
private PasswordUtil passwordUtil;
|
private PasswordUtil passwordUtil;
|
||||||
@Autowired
|
@Autowired
|
||||||
private JwtUtil jwtUtil;
|
private JwtUtil jwtUtil;
|
||||||
@Autowired
|
@Autowired
|
||||||
private UserInfoMapper userInfoMapper;
|
private UserInfoMapper userInfoMapper;
|
||||||
|
|
||||||
public UserInfo login(LoginRequest loginRequest) {
|
public UserInfo login(LoginRequest loginRequest) {
|
||||||
UserInfo userInfo = userInfoMapper.findByPlateNumber(loginRequest.getPlateNumber());
|
UserInfo userInfo = userInfoMapper.findByPlateNumber(loginRequest.getPlateNumber());
|
||||||
if (userInfo != null && passwordUtil.matches(loginRequest.getPassword(), userInfo.getPassword())) {
|
if (userInfo != null && passwordUtil.matches(loginRequest.getPassword(), userInfo.getPassword())) {
|
||||||
@@ -28,6 +35,7 @@ public class UserService {
|
|||||||
}
|
}
|
||||||
return null; // 返回null表示未找到用户
|
return null; // 返回null表示未找到用户
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserInfo loginByToken(String token) {
|
public UserInfo loginByToken(String token) {
|
||||||
Jwt jwt = jwtUtil.parse(token);
|
Jwt jwt = jwtUtil.parse(token);
|
||||||
UserInfo userInfo = userInfoMapper.findByPlateNumber(jwt.getPlateNumber());
|
UserInfo userInfo = userInfoMapper.findByPlateNumber(jwt.getPlateNumber());
|
||||||
@@ -36,11 +44,13 @@ public class UserService {
|
|||||||
}
|
}
|
||||||
return null; // 返回null表示未找到用户
|
return null; // 返回null表示未找到用户
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean register(UserInfo userInfo) {
|
public boolean register(UserInfo userInfo) {
|
||||||
// 这里可以添加注册逻辑,例如保存用户信息到数据库
|
// 这里可以添加注册逻辑,例如保存用户信息到数据库
|
||||||
// 例如:userInfoMapper.insert(userInfo);
|
// 例如:userInfoMapper.insert(userInfo);
|
||||||
return true; // 返回true表示注册成功
|
return true; // 返回true表示注册成功
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean addUser(AddUserRequest addUserRequest) {
|
public boolean addUser(AddUserRequest addUserRequest) {
|
||||||
UserInfo userInfo = new UserInfo();
|
UserInfo userInfo = new UserInfo();
|
||||||
userInfo.setPlateNumber(addUserRequest.getPlateNumber());
|
userInfo.setPlateNumber(addUserRequest.getPlateNumber());
|
||||||
@@ -53,10 +63,52 @@ public class UserService {
|
|||||||
int rowsAffected = userInfoMapper.insert(userInfo);
|
int rowsAffected = userInfoMapper.insert(userInfo);
|
||||||
return rowsAffected > 0; // 返回true表示插入成功,false表示插入失败
|
return rowsAffected > 0; // 返回true表示插入成功,false表示插入失败
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<UserInfo> getUsers(String keyword, int page, int pageSize) {
|
public List<UserInfo> getUsers(String keyword, int page, int pageSize) {
|
||||||
return userInfoMapper.getUsers(keyword, (page) * pageSize, pageSize);
|
return userInfoMapper.getUsers(keyword, (page) * pageSize, pageSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
public long countUsers(String keyword) {
|
public long countUsers(String keyword) {
|
||||||
return userInfoMapper.countUsers(keyword);
|
return userInfoMapper.countUsers(keyword);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public UserInfo getUserByPlateNumber(String plateNumber) {
|
||||||
|
return userInfoMapper.findByPlateNumber(plateNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean updateUser(UpdateRequest updateRequest) {
|
||||||
|
UserInfo userInfo = new UserInfo();
|
||||||
|
userInfo.setId(updateRequest.getId());
|
||||||
|
userInfo.setPlateNumber(updateRequest.getPlateNumber());
|
||||||
|
userInfo.setStatus(updateRequest.getStatus());
|
||||||
|
userInfo.setCarModel(updateRequest.getCarModel());
|
||||||
|
userInfo.setCarColor(updateRequest.getCarColor());
|
||||||
|
userInfo.setPurchaseYear(updateRequest.getPurchaseYear());
|
||||||
|
return userInfoMapper.updateById(userInfo) > 0; // 返回true表示更新成功,false表示更新失败
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean updateUserOil(Long id, UpdateOilRequest updateOilRequest) {
|
||||||
|
// 这里可以添加更新用户油品信息的逻辑
|
||||||
|
// 例如:userInfoMapper.updateUserOil(updateOilRequest);
|
||||||
|
UserInfo userInfo = userInfoMapper.selectById(id);
|
||||||
|
if (userInfo == null) {
|
||||||
|
return false; // 返回false表示未找到用户
|
||||||
|
} else {
|
||||||
|
userInfo.setId(id);
|
||||||
|
userInfo.setOilType(updateOilRequest.getType());
|
||||||
|
userInfo.setOilCycle(updateOilRequest.getDuration()+"月/"+updateOilRequest.getKilometers()+"公里");
|
||||||
|
userInfo.setLastOilDate(LocalDate.now());
|
||||||
|
userInfo.setNextOilDate(LocalDate.now().plusMonths(updateOilRequest.getDuration()));
|
||||||
|
return userInfoMapper.updateById(userInfo) > 0; // 返回true表示
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public boolean addRepairRecord(AddRepairRequest addRepairRequest) {
|
||||||
|
// 这里可以添加添加维修记录的逻辑
|
||||||
|
userInfoMapper.addRepairRecord(addRepairRequest.getId(), addRepairRequest.getTitle(), addRepairRequest.getDescription(),addRepairRequest.getDate()==null?null:LocalDate.parse(addRepairRequest.getDate()), addRepairRequest.getPrice());
|
||||||
|
return true; // 返回true表示添加成功,false表示添加失败
|
||||||
|
}
|
||||||
|
public List<RepairResponse> getRepairRecords(Long userId) {
|
||||||
|
// 这里可以添加获取维修记录列表的逻辑
|
||||||
|
return userInfoMapper.getRepairRecords(userId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user