feat: 添加逻辑删除字段,提升上传限制至120MB

This commit is contained in:
MaDaLei 2026-04-17 08:09:03 +08:00
parent 9008b5bece
commit 870190c709
22 changed files with 188 additions and 73 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

View File

@ -6,7 +6,6 @@ import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -119,4 +118,13 @@ public class AppointmentController {
} }
return Map.of("code", 404, "message", "预约不存在"); return Map.of("code", 404, "message", "预约不存在");
} }
@DeleteMapping("/delete")
public Map<String, Object> delete(@RequestParam Long id) {
boolean ok = appointmentService.softDelete(id);
if (!ok) {
return Map.of("code", 404, "message", "预约不存在");
}
return Map.of("code", 200, "message", "删除成功");
}
} }

View File

@ -71,9 +71,11 @@ public class FileController {
} }
String contentType = file.getContentType(); String contentType = file.getContentType();
if (contentType == null || !contentType.startsWith("image/")) { boolean isImage = contentType != null && contentType.startsWith("image/");
boolean isVideo = contentType != null && contentType.startsWith("video/");
if (!isImage && !isVideo) {
result.put("code", 400); result.put("code", 400);
result.put("message", "只能上传图片"); result.put("message", "只能上传图片或视频");
return result; return result;
} }

View File

@ -198,4 +198,13 @@ public class ReportController {
} }
return result; return result;
} }
@DeleteMapping("/delete")
public Map<String, Object> delete(@RequestParam Long id) {
boolean ok = reportService.softDelete(id);
if (!ok) {
return Map.of("code", 404, "message", "报告不存在");
}
return Map.of("code", 200, "message", "删除成功");
}
} }

View File

@ -64,6 +64,9 @@ public class StoreController {
@PutMapping("/update") @PutMapping("/update")
public Map<String, Object> update(@RequestBody Store store) { public Map<String, Object> update(@RequestBody Store store) {
Store updated = storeService.update(store); Store updated = storeService.update(store);
if (updated == null) {
return Map.of("code", 404, "message", "店铺不存在");
}
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
result.put("code", 200); result.put("code", 200);
result.put("message", "更新成功"); result.put("message", "更新成功");
@ -71,6 +74,15 @@ public class StoreController {
return result; return result;
} }
@DeleteMapping("/delete")
public Map<String, Object> delete(@RequestParam Long id) {
boolean ok = storeService.softDelete(id);
if (!ok) {
return Map.of("code", 404, "message", "店铺不存在");
}
return Map.of("code", 200, "message", "删除成功");
}
@GetMapping("/invite-code") @GetMapping("/invite-code")
public Map<String, Object> getByInviteCode(@RequestParam String code) { public Map<String, Object> getByInviteCode(@RequestParam String code) {
Store store = storeService.findByInviteCode(code); Store store = storeService.findByInviteCode(code);

View File

@ -99,7 +99,10 @@ public class UserController {
/** 老板:删除员工 */ /** 老板:删除员工 */
@DeleteMapping("/staff") @DeleteMapping("/staff")
public Map<String, Object> deleteStaff(@RequestParam Long staffId) { public Map<String, Object> deleteStaff(@RequestParam Long staffId) {
userService.deleteStaff(staffId); boolean ok = userService.deleteStaff(staffId);
if (!ok) {
return Map.of("code", 404, "message", "员工不存在");
}
return Map.of("code", 200, "message", "删除成功"); return Map.of("code", 200, "message", "删除成功");
} }

View File

@ -47,4 +47,7 @@ public class Appointment {
@Column(name = "update_time") @Column(name = "update_time")
private LocalDateTime updateTime; private LocalDateTime updateTime;
@Column(nullable = false, columnDefinition = "TINYINT(1) DEFAULT 0")
private Boolean deleted = false;
} }

View File

@ -40,4 +40,7 @@ public class Pet {
@Column(name = "update_time") @Column(name = "update_time")
private LocalDateTime updateTime; private LocalDateTime updateTime;
@Column(nullable = false, columnDefinition = "TINYINT(1) DEFAULT 0")
private Boolean deleted = false;
} }

View File

@ -2,7 +2,6 @@ package com.petstore.entity;
import jakarta.persistence.*; import jakarta.persistence.*;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data; import lombok.Data;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
@ -30,7 +29,6 @@ public class Report {
private String remark; private String remark;
@Transient @Transient
@JsonIgnore
private List<ReportImage> images = new ArrayList<>(); private List<ReportImage> images = new ArrayList<>();
@Column(name = "user_id") @Column(name = "user_id")
@ -52,4 +50,7 @@ public class Report {
@Column(name = "update_time") @Column(name = "update_time")
private LocalDateTime updateTime; private LocalDateTime updateTime;
@Column(nullable = false, columnDefinition = "TINYINT(1) DEFAULT 0")
private Boolean deleted = false;
} }

View File

@ -39,4 +39,7 @@ public class Store {
@Column(name = "update_time") @Column(name = "update_time")
private LocalDateTime updateTime; private LocalDateTime updateTime;
@Column(nullable = false, columnDefinition = "TINYINT(1) DEFAULT 0")
private Boolean deleted = false;
} }

View File

@ -35,4 +35,7 @@ public class User {
@Column(name = "update_time") @Column(name = "update_time")
private LocalDateTime updateTime; private LocalDateTime updateTime;
@Column(nullable = false, columnDefinition = "TINYINT(1) DEFAULT 0")
private Boolean deleted = false;
} }

View File

@ -6,15 +6,17 @@ import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List; import java.util.List;
import java.util.Optional;
public interface AppointmentMapper extends JpaRepository<Appointment, Long> { public interface AppointmentMapper extends JpaRepository<Appointment, Long> {
List<Appointment> findByUserId(Long userId); List<Appointment> findByUserIdAndDeletedFalse(Long userId);
List<Appointment> findByUserIdAndStatus(Long userId, String status); List<Appointment> findByUserIdAndStatusAndDeletedFalse(Long userId, String status);
List<Appointment> findByStoreId(Long storeId); List<Appointment> findByStoreIdAndDeletedFalse(Long storeId);
List<Appointment> findByStoreIdAndStatus(Long storeId, String status); List<Appointment> findByStoreIdAndStatusAndDeletedFalse(Long storeId, String status);
Page<Appointment> findByUserId(Long userId, Pageable pageable); Page<Appointment> findByUserIdAndDeletedFalse(Long userId, Pageable pageable);
Page<Appointment> findByUserIdAndStatus(Long userId, String status, Pageable pageable); Page<Appointment> findByUserIdAndStatusAndDeletedFalse(Long userId, String status, Pageable pageable);
Page<Appointment> findByStoreId(Long storeId, Pageable pageable); Page<Appointment> findByStoreIdAndDeletedFalse(Long storeId, Pageable pageable);
Page<Appointment> findByStoreIdAndStatus(Long storeId, String status, Pageable pageable); Page<Appointment> findByStoreIdAndStatusAndDeletedFalse(Long storeId, String status, Pageable pageable);
Optional<Appointment> findByIdAndDeletedFalse(Long id);
} }

View File

@ -6,12 +6,14 @@ import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param; import org.springframework.data.repository.query.Param;
import java.util.List; import java.util.List;
import java.util.Optional;
public interface PetMapper extends JpaRepository<Pet, Long> { public interface PetMapper extends JpaRepository<Pet, Long> {
List<Pet> findByOwnerUserIdOrderByUpdateTimeDesc(Long ownerUserId); List<Pet> findByOwnerUserIdAndDeletedFalseOrderByUpdateTimeDesc(Long ownerUserId);
/** 本店预约中关联过的宠物(预约.pet_id 指向该宠物) */ /** 本店预约中关联过的宠物(预约.pet_id 指向该宠物) */
@Query("SELECT DISTINCT p FROM Pet p, Appointment a WHERE a.petId = p.id AND a.storeId = :storeId ORDER BY p.updateTime DESC") @Query("SELECT DISTINCT p FROM Pet p, Appointment a WHERE a.petId = p.id AND a.storeId = :storeId AND p.deleted = false AND a.deleted = false ORDER BY p.updateTime DESC")
List<Pet> findDistinctPetsServedAtStore(@Param("storeId") Long storeId); List<Pet> findDistinctPetsServedAtStore(@Param("storeId") Long storeId);
Optional<Pet> findByIdAndDeletedFalse(Long id);
} }

View File

@ -9,22 +9,24 @@ import java.util.List;
import java.util.Optional; import java.util.Optional;
public interface ReportMapper extends JpaRepository<Report, Long> { public interface ReportMapper extends JpaRepository<Report, Long> {
Optional<Report> findFirstByAppointmentIdOrderByCreateTimeDesc(Long appointmentId); Optional<Report> findFirstByAppointmentIdAndDeletedFalseOrderByCreateTimeDesc(Long appointmentId);
Optional<Report> findFirstByReportToken(String reportToken); Optional<Report> findFirstByReportTokenAndDeletedFalse(String reportToken);
List<Report> findByStoreIdOrderByCreateTimeDesc(Long storeId); List<Report> findByStoreIdAndDeletedFalseOrderByCreateTimeDesc(Long storeId);
List<Report> findByUserIdOrderByCreateTimeDesc(Long userId); List<Report> findByUserIdAndDeletedFalseOrderByCreateTimeDesc(Long userId);
List<Report> findByStoreIdAndUserIdOrderByCreateTimeDesc(Long storeId, Long userId); List<Report> findByStoreIdAndUserIdAndDeletedFalseOrderByCreateTimeDesc(Long storeId, Long userId);
List<Report> findAllByOrderByCreateTimeDesc(); List<Report> findAllByDeletedFalseOrderByCreateTimeDesc();
Page<Report> findByStoreId(Long storeId, Pageable pageable); Page<Report> findByStoreIdAndDeletedFalse(Long storeId, Pageable pageable);
Page<Report> findByUserId(Long userId, Pageable pageable); Page<Report> findByUserIdAndDeletedFalse(Long userId, Pageable pageable);
Page<Report> findByStoreIdAndUserId(Long storeId, Long userId, Pageable pageable); Page<Report> findByStoreIdAndUserIdAndDeletedFalse(Long storeId, Long userId, Pageable pageable);
Page<Report> findByDeletedFalse(Pageable pageable);
Optional<Report> findByIdAndDeletedFalse(Long id);
} }

View File

@ -3,6 +3,11 @@ package com.petstore.mapper;
import com.petstore.entity.Store; import com.petstore.entity.Store;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List;
import java.util.Optional;
public interface StoreMapper extends JpaRepository<Store, Long> { public interface StoreMapper extends JpaRepository<Store, Long> {
Store findByInviteCode(String inviteCode); Store findByInviteCodeAndDeletedFalse(String inviteCode);
Optional<Store> findByIdAndDeletedFalse(Long id);
List<Store> findAllByDeletedFalse();
} }

View File

@ -4,9 +4,11 @@ import com.petstore.entity.User;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List; import java.util.List;
import java.util.Optional;
public interface UserMapper extends JpaRepository<User, Long> { public interface UserMapper extends JpaRepository<User, Long> {
User findByUsername(String username); User findByUsernameAndDeletedFalse(String username);
User findByPhone(String phone); User findByPhoneAndDeletedFalse(String phone);
List<User> findByStoreId(Long storeId); List<User> findByStoreIdAndDeletedFalse(Long storeId);
Optional<User> findByIdAndDeletedFalse(Long id);
} }

View File

@ -19,22 +19,22 @@ public class AppointmentService {
// 员工查看自己的预约 // 员工查看自己的预约
public List<Appointment> getByUserId(Long userId) { public List<Appointment> getByUserId(Long userId) {
return appointmentMapper.findByUserId(userId); return appointmentMapper.findByUserIdAndDeletedFalse(userId);
} }
// 老板查看本店所有预约 // 老板查看本店所有预约
public List<Appointment> getByStoreId(Long storeId) { public List<Appointment> getByStoreId(Long storeId) {
return appointmentMapper.findByStoreId(storeId); return appointmentMapper.findByStoreIdAndDeletedFalse(storeId);
} }
// 员工按状态查 // 员工按状态查
public List<Appointment> getByUserIdAndStatus(Long userId, String status) { public List<Appointment> getByUserIdAndStatus(Long userId, String status) {
return appointmentMapper.findByUserIdAndStatus(userId, status); return appointmentMapper.findByUserIdAndStatusAndDeletedFalse(userId, status);
} }
// 老板按状态查 // 老板按状态查
public List<Appointment> getByStoreIdAndStatus(Long storeId, String status) { public List<Appointment> getByStoreIdAndStatus(Long storeId, String status) {
return appointmentMapper.findByStoreIdAndStatus(storeId, status); return appointmentMapper.findByStoreIdAndStatusAndDeletedFalse(storeId, status);
} }
public Page<Appointment> pageByScope(Long userId, Long storeId, String status, int pageNo, int pageSize) { public Page<Appointment> pageByScope(Long userId, Long storeId, String status, int pageNo, int pageSize) {
@ -46,29 +46,30 @@ public class AppointmentService {
boolean hasStatus = status != null && !status.isBlank(); boolean hasStatus = status != null && !status.isBlank();
if (storeId != null) { if (storeId != null) {
return hasStatus return hasStatus
? appointmentMapper.findByStoreIdAndStatus(storeId, status, pageable) ? appointmentMapper.findByStoreIdAndStatusAndDeletedFalse(storeId, status, pageable)
: appointmentMapper.findByStoreId(storeId, pageable); : appointmentMapper.findByStoreIdAndDeletedFalse(storeId, pageable);
} }
if (userId != null) { if (userId != null) {
return hasStatus return hasStatus
? appointmentMapper.findByUserIdAndStatus(userId, status, pageable) ? appointmentMapper.findByUserIdAndStatusAndDeletedFalse(userId, status, pageable)
: appointmentMapper.findByUserId(userId, pageable); : appointmentMapper.findByUserIdAndDeletedFalse(userId, pageable);
} }
return Page.empty(pageable); return Page.empty(pageable);
} }
public Appointment getById(Long id) { public Appointment getById(Long id) {
return appointmentMapper.findById(id).orElse(null); return appointmentMapper.findByIdAndDeletedFalse(id).orElse(null);
} }
public Appointment create(Appointment appointment) { public Appointment create(Appointment appointment) {
appointment.setCreateTime(LocalDateTime.now()); appointment.setCreateTime(LocalDateTime.now());
appointment.setUpdateTime(LocalDateTime.now()); appointment.setUpdateTime(LocalDateTime.now());
appointment.setDeleted(false);
return appointmentMapper.save(appointment); return appointmentMapper.save(appointment);
} }
public Appointment updateStatus(Long id, String status) { public Appointment updateStatus(Long id, String status) {
Appointment appointment = appointmentMapper.findById(id).orElse(null); Appointment appointment = appointmentMapper.findByIdAndDeletedFalse(id).orElse(null);
if (appointment != null) { if (appointment != null) {
appointment.setStatus(status); appointment.setStatus(status);
appointment.setUpdateTime(LocalDateTime.now()); appointment.setUpdateTime(LocalDateTime.now());
@ -79,7 +80,7 @@ public class AppointmentService {
/** 开始服务:状态变为进行中,同时指定技师为当前用户 */ /** 开始服务:状态变为进行中,同时指定技师为当前用户 */
public Appointment startService(Long appointmentId, Long staffUserId) { public Appointment startService(Long appointmentId, Long staffUserId) {
Appointment appointment = appointmentMapper.findById(appointmentId).orElse(null); Appointment appointment = appointmentMapper.findByIdAndDeletedFalse(appointmentId).orElse(null);
if (appointment != null) { if (appointment != null) {
appointment.setStatus("doing"); appointment.setStatus("doing");
appointment.setAssignedUserId(staffUserId); appointment.setAssignedUserId(staffUserId);
@ -88,4 +89,15 @@ public class AppointmentService {
} }
return null; return null;
} }
public boolean softDelete(Long id) {
Appointment appointment = appointmentMapper.findByIdAndDeletedFalse(id).orElse(null);
if (appointment == null) {
return false;
}
appointment.setDeleted(true);
appointment.setUpdateTime(LocalDateTime.now());
appointmentMapper.save(appointment);
return true;
}
} }

View File

@ -20,7 +20,7 @@ public class PetService {
if (ownerUserId == null) { if (ownerUserId == null) {
return List.of(); return List.of();
} }
return petMapper.findByOwnerUserIdOrderByUpdateTimeDesc(ownerUserId); return petMapper.findByOwnerUserIdAndDeletedFalseOrderByUpdateTimeDesc(ownerUserId);
} }
/** 商家/员工:本店预约中关联过的宠物(预约带 pet_id */ /** 商家/员工:本店预约中关联过的宠物(预约带 pet_id */
@ -43,6 +43,7 @@ public class PetService {
} }
pet.setCreateTime(LocalDateTime.now()); pet.setCreateTime(LocalDateTime.now());
pet.setUpdateTime(LocalDateTime.now()); pet.setUpdateTime(LocalDateTime.now());
pet.setDeleted(false);
Pet saved = petMapper.save(pet); Pet saved = petMapper.save(pet);
return Map.of("code", 200, "message", "保存成功", "data", saved); return Map.of("code", 200, "message", "保存成功", "data", saved);
} }
@ -51,7 +52,7 @@ public class PetService {
if (input.getId() == null) { if (input.getId() == null) {
return Map.of("code", 400, "message", "缺少宠物ID"); return Map.of("code", 400, "message", "缺少宠物ID");
} }
Optional<Pet> opt = petMapper.findById(input.getId()); Optional<Pet> opt = petMapper.findByIdAndDeletedFalse(input.getId());
if (opt.isEmpty()) { if (opt.isEmpty()) {
return Map.of("code", 404, "message", "宠物不存在"); return Map.of("code", 404, "message", "宠物不存在");
} }
@ -84,7 +85,7 @@ public class PetService {
} }
public Map<String, Object> delete(Long petId, Long operatorUserId, String role) { public Map<String, Object> delete(Long petId, Long operatorUserId, String role) {
Optional<Pet> opt = petMapper.findById(petId); Optional<Pet> opt = petMapper.findByIdAndDeletedFalse(petId);
if (opt.isEmpty()) { if (opt.isEmpty()) {
return Map.of("code", 404, "message", "宠物不存在"); return Map.of("code", 404, "message", "宠物不存在");
} }
@ -92,7 +93,9 @@ public class PetService {
if (!"customer".equals(role) || !pet.getOwnerUserId().equals(operatorUserId)) { if (!"customer".equals(role) || !pet.getOwnerUserId().equals(operatorUserId)) {
return Map.of("code", 403, "message", "无权删除"); return Map.of("code", 403, "message", "无权删除");
} }
petMapper.deleteById(petId); pet.setDeleted(true);
pet.setUpdateTime(LocalDateTime.now());
petMapper.save(pet);
return Map.of("code", 200, "message", "已删除"); return Map.of("code", 200, "message", "已删除");
} }
} }

View File

@ -27,7 +27,7 @@ public class ReportService {
// 填充冗余字段并自动完成预约 // 填充冗余字段并自动完成预约
if (report.getAppointmentId() != null) { if (report.getAppointmentId() != null) {
Appointment appt = appointmentMapper.findById(report.getAppointmentId()).orElse(null); Appointment appt = appointmentMapper.findByIdAndDeletedFalse(report.getAppointmentId()).orElse(null);
if (appt != null) { if (appt != null) {
report.setPetName(appt.getPetName()); report.setPetName(appt.getPetName());
report.setServiceType(appt.getServiceType()); report.setServiceType(appt.getServiceType());
@ -35,7 +35,7 @@ public class ReportService {
report.setStoreId(appt.getStoreId()); report.setStoreId(appt.getStoreId());
// 技师取预约分配的技师开始服务时指定的 // 技师取预约分配的技师开始服务时指定的
if (appt.getAssignedUserId() != null) { if (appt.getAssignedUserId() != null) {
User staff = userMapper.findById(appt.getAssignedUserId()).orElse(null); User staff = userMapper.findByIdAndDeletedFalse(appt.getAssignedUserId()).orElse(null);
if (staff != null) { if (staff != null) {
report.setUserId(staff.getId()); report.setUserId(staff.getId());
report.setStaffName(staff.getName()); report.setStaffName(staff.getName());
@ -49,7 +49,7 @@ public class ReportService {
} }
// 如果预约没分配技师则用当前操作人 // 如果预约没分配技师则用当前操作人
if (report.getUserId() != null && report.getStaffName() == null) { if (report.getUserId() != null && report.getStaffName() == null) {
User staff = userMapper.findById(report.getUserId()).orElse(null); User staff = userMapper.findByIdAndDeletedFalse(report.getUserId()).orElse(null);
if (staff != null) { if (staff != null) {
report.setStaffName(staff.getName()); report.setStaffName(staff.getName());
if (report.getStoreId() == null) { if (report.getStoreId() == null) {
@ -60,6 +60,7 @@ public class ReportService {
report.setCreateTime(LocalDateTime.now()); report.setCreateTime(LocalDateTime.now());
report.setUpdateTime(LocalDateTime.now()); report.setUpdateTime(LocalDateTime.now());
report.setDeleted(false);
// 先保存 Report 以获取生成的 ID // 先保存 Report 以获取生成的 ID
Report saved = reportMapper.save(report); Report saved = reportMapper.save(report);
@ -100,26 +101,26 @@ public class ReportService {
if (appointmentId == null) { if (appointmentId == null) {
return null; return null;
} }
return enrichImages(reportMapper.findFirstByAppointmentIdOrderByCreateTimeDesc(appointmentId).orElse(null)); return enrichImages(reportMapper.findFirstByAppointmentIdAndDeletedFalseOrderByCreateTimeDesc(appointmentId).orElse(null));
} }
public Report getByToken(String token) { public Report getByToken(String token) {
if (token == null || token.isBlank()) { if (token == null || token.isBlank()) {
return null; return null;
} }
return enrichImages(reportMapper.findFirstByReportToken(token).orElse(null)); return enrichImages(reportMapper.findFirstByReportTokenAndDeletedFalse(token).orElse(null));
} }
public List<Report> list(Long storeId, Long userId) { public List<Report> list(Long storeId, Long userId) {
List<Report> reports; List<Report> reports;
if (storeId != null && userId != null) { if (storeId != null && userId != null) {
reports = reportMapper.findByStoreIdAndUserIdOrderByCreateTimeDesc(storeId, userId); reports = reportMapper.findByStoreIdAndUserIdAndDeletedFalseOrderByCreateTimeDesc(storeId, userId);
} else if (storeId != null) { } else if (storeId != null) {
reports = reportMapper.findByStoreIdOrderByCreateTimeDesc(storeId); reports = reportMapper.findByStoreIdAndDeletedFalseOrderByCreateTimeDesc(storeId);
} else if (userId != null) { } else if (userId != null) {
reports = reportMapper.findByUserIdOrderByCreateTimeDesc(userId); reports = reportMapper.findByUserIdAndDeletedFalseOrderByCreateTimeDesc(userId);
} else { } else {
reports = reportMapper.findAllByOrderByCreateTimeDesc(); reports = reportMapper.findAllByDeletedFalseOrderByCreateTimeDesc();
} }
return enrichImages(reports); return enrichImages(reports);
} }
@ -132,16 +133,27 @@ public class ReportService {
); );
Page<Report> paged; Page<Report> paged;
if (storeId != null && userId != null) { if (storeId != null && userId != null) {
paged = reportMapper.findByStoreIdAndUserId(storeId, userId, pageable); paged = reportMapper.findByStoreIdAndUserIdAndDeletedFalse(storeId, userId, pageable);
} else if (storeId != null) { } else if (storeId != null) {
paged = reportMapper.findByStoreId(storeId, pageable); paged = reportMapper.findByStoreIdAndDeletedFalse(storeId, pageable);
} else if (userId != null) { } else if (userId != null) {
paged = reportMapper.findByUserId(userId, pageable); paged = reportMapper.findByUserIdAndDeletedFalse(userId, pageable);
} else { } else {
paged = reportMapper.findAll(pageable); paged = reportMapper.findByDeletedFalse(pageable);
} }
// 填充图片 // 填充图片
enrichImages(paged.getContent()); enrichImages(paged.getContent());
return paged; return paged;
} }
public boolean softDelete(Long id) {
Report report = reportMapper.findByIdAndDeletedFalse(id).orElse(null);
if (report == null) {
return false;
}
report.setDeleted(true);
report.setUpdateTime(LocalDateTime.now());
reportMapper.save(report);
return true;
}
} }

View File

@ -18,27 +18,42 @@ public class StoreService {
store.setInviteCode(generateInviteCode()); store.setInviteCode(generateInviteCode());
store.setCreateTime(LocalDateTime.now()); store.setCreateTime(LocalDateTime.now());
store.setUpdateTime(LocalDateTime.now()); store.setUpdateTime(LocalDateTime.now());
store.setDeleted(false);
return storeMapper.save(store); return storeMapper.save(store);
} }
public Store findById(Long id) { public Store findById(Long id) {
return storeMapper.findById(id).orElse(null); return storeMapper.findByIdAndDeletedFalse(id).orElse(null);
} }
public Store findByInviteCode(String code) { public Store findByInviteCode(String code) {
return storeMapper.findByInviteCode(code); return storeMapper.findByInviteCodeAndDeletedFalse(code);
} }
/** C 端预约:列出全部门店供选择 */ /** C 端预约:列出全部门店供选择 */
public List<Store> listAll() { public List<Store> listAll() {
return storeMapper.findAll(); return storeMapper.findAllByDeletedFalse();
} }
public Store update(Store store) { public Store update(Store store) {
store.setUpdateTime(LocalDateTime.now()); store.setUpdateTime(LocalDateTime.now());
if (store.getDeleted() == null) {
store.setDeleted(false);
}
return storeMapper.save(store); return storeMapper.save(store);
} }
public boolean softDelete(Long id) {
Store store = storeMapper.findByIdAndDeletedFalse(id).orElse(null);
if (store == null) {
return false;
}
store.setDeleted(true);
store.setUpdateTime(LocalDateTime.now());
storeMapper.save(store);
return true;
}
private String generateInviteCode() { private String generateInviteCode() {
return UUID.randomUUID().toString().replace("-", "").substring(0, 8).toUpperCase(); return UUID.randomUUID().toString().replace("-", "").substring(0, 8).toUpperCase();
} }

View File

@ -17,7 +17,7 @@ public class UserService {
private final StoreMapper storeMapper; private final StoreMapper storeMapper;
public Map<String, Object> registerBoss(String storeName, String bossName, String phone, String password) { public Map<String, Object> registerBoss(String storeName, String bossName, String phone, String password) {
if (userMapper.findByPhone(phone) != null) { if (userMapper.findByPhoneAndDeletedFalse(phone) != null) {
return Map.of("code", 400, "message", "手机号已注册"); return Map.of("code", 400, "message", "手机号已注册");
} }
@ -28,6 +28,7 @@ public class UserService {
store.setInviteCode(UUID.randomUUID().toString().replace("-", "").substring(0, 8).toUpperCase()); store.setInviteCode(UUID.randomUUID().toString().replace("-", "").substring(0, 8).toUpperCase());
store.setCreateTime(LocalDateTime.now()); store.setCreateTime(LocalDateTime.now());
store.setUpdateTime(LocalDateTime.now()); store.setUpdateTime(LocalDateTime.now());
store.setDeleted(false);
store = storeMapper.save(store); store = storeMapper.save(store);
User boss = new User(); User boss = new User();
@ -39,6 +40,7 @@ public class UserService {
boss.setRole("boss"); boss.setRole("boss");
boss.setCreateTime(LocalDateTime.now()); boss.setCreateTime(LocalDateTime.now());
boss.setUpdateTime(LocalDateTime.now()); boss.setUpdateTime(LocalDateTime.now());
boss.setDeleted(false);
boss = userMapper.save(boss); boss = userMapper.save(boss);
store.setOwnerId(boss.getId()); store.setOwnerId(boss.getId());
@ -65,7 +67,7 @@ public class UserService {
if (phone == null || !phone.matches("^1\\d{10}$")) { if (phone == null || !phone.matches("^1\\d{10}$")) {
return Map.of("code", 400, "message", "手机号格式不正确"); return Map.of("code", 400, "message", "手机号格式不正确");
} }
User user = userMapper.findByPhone(phone); User user = userMapper.findByPhoneAndDeletedFalse(phone);
if (user == null) { if (user == null) {
user = new User(); user = new User();
user.setUsername(phone); user.setUsername(phone);
@ -75,11 +77,12 @@ public class UserService {
user.setRole("customer"); user.setRole("customer");
user.setCreateTime(LocalDateTime.now()); user.setCreateTime(LocalDateTime.now());
user.setUpdateTime(LocalDateTime.now()); user.setUpdateTime(LocalDateTime.now());
user.setDeleted(false);
user = userMapper.save(user); user = userMapper.save(user);
} }
Store store = null; Store store = null;
if (user.getStoreId() != null) { if (user.getStoreId() != null) {
store = storeMapper.findById(user.getStoreId()).orElse(null); store = storeMapper.findByIdAndDeletedFalse(user.getStoreId()).orElse(null);
} }
Map<String, Object> data = new HashMap<>(); Map<String, Object> data = new HashMap<>();
data.put("user", user); data.put("user", user);
@ -88,10 +91,10 @@ public class UserService {
} }
public Map<String, Object> registerStaff(String phone, String password, String name, String inviteCode) { public Map<String, Object> registerStaff(String phone, String password, String name, String inviteCode) {
if (userMapper.findByPhone(phone) != null) { if (userMapper.findByPhoneAndDeletedFalse(phone) != null) {
return Map.of("code", 400, "message", "手机号已注册"); return Map.of("code", 400, "message", "手机号已注册");
} }
Store store = storeMapper.findByInviteCode(inviteCode); Store store = storeMapper.findByInviteCodeAndDeletedFalse(inviteCode);
if (store == null) { if (store == null) {
return Map.of("code", 400, "message", "邀请码无效"); return Map.of("code", 400, "message", "邀请码无效");
} }
@ -104,6 +107,7 @@ public class UserService {
staff.setRole("staff"); staff.setRole("staff");
staff.setCreateTime(LocalDateTime.now()); staff.setCreateTime(LocalDateTime.now());
staff.setUpdateTime(LocalDateTime.now()); staff.setUpdateTime(LocalDateTime.now());
staff.setDeleted(false);
staff = userMapper.save(staff); staff = userMapper.save(staff);
Map<String, Object> data = new HashMap<>(); Map<String, Object> data = new HashMap<>();
data.put("user", staff); data.put("user", staff);
@ -115,7 +119,7 @@ public class UserService {
if (storeId == null) { if (storeId == null) {
return Map.of("code", 400, "message", "店铺ID不能为空"); return Map.of("code", 400, "message", "店铺ID不能为空");
} }
if (userMapper.findByPhone(phone) != null) { if (userMapper.findByPhoneAndDeletedFalse(phone) != null) {
return Map.of("code", 400, "message", "手机号已存在"); return Map.of("code", 400, "message", "手机号已存在");
} }
String pwd = String.format("%06d", (int)(Math.random() * 999999)); String pwd = String.format("%06d", (int)(Math.random() * 999999));
@ -128,25 +132,33 @@ public class UserService {
staff.setRole("staff"); staff.setRole("staff");
staff.setCreateTime(LocalDateTime.now()); staff.setCreateTime(LocalDateTime.now());
staff.setUpdateTime(LocalDateTime.now()); staff.setUpdateTime(LocalDateTime.now());
staff.setDeleted(false);
staff = userMapper.save(staff); staff = userMapper.save(staff);
return Map.of("code", 200, "message", "创建成功,初始密码:" + pwd, "data", staff); return Map.of("code", 200, "message", "创建成功,初始密码:" + pwd, "data", staff);
} }
public List<User> getStaffList(Long storeId) { public List<User> getStaffList(Long storeId) {
return userMapper.findByStoreId(storeId); return userMapper.findByStoreIdAndDeletedFalse(storeId);
} }
public void deleteStaff(Long staffId) { public boolean deleteStaff(Long staffId) {
userMapper.deleteById(staffId); User user = userMapper.findByIdAndDeletedFalse(staffId).orElse(null);
if (user == null) {
return false;
}
user.setDeleted(true);
user.setUpdateTime(LocalDateTime.now());
userMapper.save(user);
return true;
} }
public User findById(Long id) { public User findById(Long id) {
return userMapper.findById(id).orElse(null); return userMapper.findByIdAndDeletedFalse(id).orElse(null);
} }
public Map<String, Object> updateUser(Map<String, Object> params) { public Map<String, Object> updateUser(Map<String, Object> params) {
Long userId = Long.valueOf(params.get("id").toString()); Long userId = Long.valueOf(params.get("id").toString());
User user = userMapper.findById(userId).orElse(null); User user = userMapper.findByIdAndDeletedFalse(userId).orElse(null);
if (user == null) { if (user == null) {
return Map.of("code", 404, "message", "用户不存在"); return Map.of("code", 404, "message", "用户不存在");
} }
@ -161,7 +173,7 @@ public class UserService {
return Map.of("code", 400, "message", "验证码错误"); return Map.of("code", 400, "message", "验证码错误");
} }
// 检查手机号是否被占用 // 检查手机号是否被占用
User existing = userMapper.findByPhone(newPhone); User existing = userMapper.findByPhoneAndDeletedFalse(newPhone);
if (existing != null && !existing.getId().equals(userId)) { if (existing != null && !existing.getId().equals(userId)) {
return Map.of("code", 400, "message", "手机号已被占用"); return Map.of("code", 400, "message", "手机号已被占用");
} }

View File

@ -21,7 +21,8 @@ spring:
format_sql: true format_sql: true
servlet: servlet:
multipart: multipart:
max-file-size: 10MB max-file-size: 120MB
max-request-size: 120MB
server: server:
port: 8080 port: 8080