feat(car): 实现车辆管理硬删除功能
- 在控制器中将删除方法改为硬删除(物理删除),绕过逻辑删除注解 - 在数据访问层添加硬删除SQL映射方法,支持单条和批量删除 - 在服务层定义硬删除接口方法并实现具体逻辑 - 添加空值校验确保删除操作的安全性 - 注释说明硬删除与逻辑删除的区别和用途
This commit is contained in:
@@ -144,7 +144,8 @@ public class HjmCarController extends BaseController {
|
|||||||
@Operation(summary = "删除黄家明_车辆管理")
|
@Operation(summary = "删除黄家明_车辆管理")
|
||||||
@DeleteMapping("/{id}")
|
@DeleteMapping("/{id}")
|
||||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||||
if (hjmCarService.removeById(id)) {
|
// 硬删除(物理删除),不走 @TableLogic 逻辑删除
|
||||||
|
if (hjmCarService.hardRemoveById(id)) {
|
||||||
return success("删除成功");
|
return success("删除成功");
|
||||||
}
|
}
|
||||||
return fail("删除失败");
|
return fail("删除失败");
|
||||||
@@ -177,7 +178,8 @@ public class HjmCarController extends BaseController {
|
|||||||
@Operation(summary = "批量删除黄家明_车辆管理")
|
@Operation(summary = "批量删除黄家明_车辆管理")
|
||||||
@DeleteMapping("/batch")
|
@DeleteMapping("/batch")
|
||||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||||
if (hjmCarService.removeByIds(ids)) {
|
// 硬删除(物理删除),不走 @TableLogic 逻辑删除
|
||||||
|
if (hjmCarService.hardRemoveByIds(ids)) {
|
||||||
return success("删除成功");
|
return success("删除成功");
|
||||||
}
|
}
|
||||||
return fail("删除失败");
|
return fail("删除失败");
|
||||||
|
|||||||
@@ -5,8 +5,10 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.gxwebsoft.hjm.entity.HjmCar;
|
import com.gxwebsoft.hjm.entity.HjmCar;
|
||||||
import com.gxwebsoft.hjm.param.HjmCarParam;
|
import com.gxwebsoft.hjm.param.HjmCarParam;
|
||||||
|
import org.apache.ibatis.annotations.Delete;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -44,4 +46,23 @@ public interface HjmCarMapper extends BaseMapper<HjmCar> {
|
|||||||
|
|
||||||
@InterceptorIgnore(tenantLine = "true")
|
@InterceptorIgnore(tenantLine = "true")
|
||||||
HjmCar getByCode(String code);
|
HjmCar getByCode(String code);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 硬删除:绕过 MyBatis-Plus 逻辑删除(@TableLogic)。
|
||||||
|
*/
|
||||||
|
@Delete("DELETE FROM hjm_car WHERE id = #{id}")
|
||||||
|
int hardDeleteById(@Param("id") Integer id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 硬删除:批量删除,绕过 MyBatis-Plus 逻辑删除(@TableLogic)。
|
||||||
|
*/
|
||||||
|
@Delete({
|
||||||
|
"<script>",
|
||||||
|
"DELETE FROM hjm_car WHERE id IN",
|
||||||
|
"<foreach collection='ids' item='id' open='(' separator=',' close=')'>",
|
||||||
|
"#{id}",
|
||||||
|
"</foreach>",
|
||||||
|
"</script>"
|
||||||
|
})
|
||||||
|
int hardDeleteBatchIds(@Param("ids") Collection<Integer> ids);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,4 +44,14 @@ public interface HjmCarService extends IService<HjmCar> {
|
|||||||
boolean updateByGpsNo(HjmCar byGpsNo);
|
boolean updateByGpsNo(HjmCar byGpsNo);
|
||||||
|
|
||||||
HjmCar getByCode(String code);
|
HjmCar getByCode(String code);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 硬删除(物理删除),绕过 @TableLogic 逻辑删除。
|
||||||
|
*/
|
||||||
|
boolean hardRemoveById(Integer id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 硬删除(物理删除),绕过 @TableLogic 逻辑删除。
|
||||||
|
*/
|
||||||
|
boolean hardRemoveByIds(List<Integer> ids);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -127,6 +127,22 @@ public class HjmCarServiceImpl extends ServiceImpl<HjmCarMapper, HjmCar> impleme
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hardRemoveById(Integer id) {
|
||||||
|
if (id == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return baseMapper.hardDeleteById(id) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hardRemoveByIds(List<Integer> ids) {
|
||||||
|
if (ids == null || ids.isEmpty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return baseMapper.hardDeleteBatchIds(ids) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user