删除模块
This commit is contained in:
parent
7b15fad32e
commit
94e07f2848
|
@ -0,0 +1,36 @@
|
||||||
|
package com.wxjw.controller.openapi;
|
||||||
|
|
||||||
|
import com.wxjw.common.BaseResponse;
|
||||||
|
import com.wxjw.common.ResultUtil;
|
||||||
|
import com.wxjw.dal.dao.ExcelInfoMapper;
|
||||||
|
import com.wxjw.dal.pojo.ErrorCode;
|
||||||
|
import com.wxjw.dal.pojo.data.DeleteFile.DeleteFileData;
|
||||||
|
import com.wxjw.dal.pojo.entity.ExcelInfoEntity;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Controller 删除文件(仅需删除数据库)
|
||||||
|
*
|
||||||
|
* @author 筱锋xiao_lfeng
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/openapi/delete")
|
||||||
|
public class DeleteFileController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ExcelInfoMapper excelInfoMapper;
|
||||||
|
|
||||||
|
@PostMapping("/file")
|
||||||
|
public ResponseEntity<BaseResponse<Object>> deleteFile(@RequestBody DeleteFileData requestBody) {
|
||||||
|
if ("deletefile".equals(requestBody.getAction())) {
|
||||||
|
return d;
|
||||||
|
} else {
|
||||||
|
return ResultUtil.error(ErrorCode.PARAMETER_ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
package com.wxjw.dal.dao;
|
package com.wxjw.dal.dao;
|
||||||
|
|
||||||
import com.wxjw.dal.pojo.entity.ExcelInfoEntity;
|
import com.wxjw.dal.pojo.entity.ExcelInfoEntity;
|
||||||
|
import org.apache.ibatis.annotations.Delete;
|
||||||
import org.apache.ibatis.annotations.Insert;
|
import org.apache.ibatis.annotations.Insert;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.apache.ibatis.annotations.Select;
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
@ -43,6 +44,13 @@ public interface ExcelInfoMapper {
|
||||||
@Select("SELECT * FROM excel_file_handling.excel_info WHERE id = #{id}")
|
@Select("SELECT * FROM excel_file_handling.excel_info WHERE id = #{id}")
|
||||||
ExcelInfoEntity getExcelForId(int id);
|
ExcelInfoEntity getExcelForId(int id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param id 序号
|
||||||
|
* @return 是否删除成功
|
||||||
|
*/
|
||||||
|
@Delete("DELETE FROM excel_file_handling.excel_info WHERE id = #{id}")
|
||||||
|
boolean deleteExcelForId(int id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param excelInfoEntity excel
|
* @param excelInfoEntity excel
|
||||||
* @return 是否插入成功
|
* @return 是否插入成功
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
package com.wxjw.dal.pojo.data.DeleteFile;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data 删除文件
|
||||||
|
*
|
||||||
|
* @author 筱锋xiao_lfeng
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
public class DeleteFileData {
|
||||||
|
private String action;
|
||||||
|
private int nodeId;
|
||||||
|
}
|
40
src/main/java/com/wxjw/service/DeleteFileService.java
Normal file
40
src/main/java/com/wxjw/service/DeleteFileService.java
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
package com.wxjw.service;
|
||||||
|
|
||||||
|
import com.wxjw.common.BaseResponse;
|
||||||
|
import com.wxjw.common.ResultUtil;
|
||||||
|
import com.wxjw.dal.dao.ExcelInfoMapper;
|
||||||
|
import com.wxjw.dal.pojo.ErrorCode;
|
||||||
|
import com.wxjw.dal.pojo.data.DeleteFile.DeleteFileData;
|
||||||
|
import com.wxjw.dal.pojo.entity.ExcelInfoEntity;
|
||||||
|
import lombok.Getter;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Service 删除文件控制器(不删除文件,删除数据库记录)
|
||||||
|
*
|
||||||
|
* @author 筱锋xiao_lfeng
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class DeleteFileService {
|
||||||
|
private final ExcelInfoMapper excelInfoMapper;
|
||||||
|
@Getter
|
||||||
|
private ResponseEntity<BaseResponse<Object>> returnResult;
|
||||||
|
|
||||||
|
public DeleteFileService(ExcelInfoMapper excelInfoMapper) {
|
||||||
|
this.excelInfoMapper = excelInfoMapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteFile(@NotNull DeleteFileData requestBody) {
|
||||||
|
// 检查数据是否存在
|
||||||
|
ExcelInfoEntity excelInfo = excelInfoMapper.getExcelForId(requestBody.getNodeId());
|
||||||
|
if (excelInfo != null && excelInfo.getId() != null) {
|
||||||
|
// 查找到数据执行删除
|
||||||
|
excelInfoMapper.deleteExcelForId(excelInfo.getId());
|
||||||
|
returnResult = ResultUtil.success("删除成功");
|
||||||
|
} else {
|
||||||
|
returnResult = ResultUtil.error(ErrorCode.DATA_IS_EMPTY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user