1.Controller
@Api(tags="bs_file_store") @RestController @RequestMapping("/test/bsFileStore") @Slf4j public class BsFileStoreController extends JeecgController<BsFileStore, IBsFileStoreService> { @Autowired private IBsFileStoreService bsFileStoreService; /** * 通过id和storeType删除 * * @param id * @return */ @AutoLog(value = "bs_file_store-通过id和storeType删除") @ApiOperation(value="bs_file_store-通过id删除", notes="bs_file_store-通过id和storeType删除") @DeleteMapping(value = "/delete") public Result<?> delete(@RequestParam(name="id",required=true) String id,@RequestParam(name="storeType",required=true) String storeType) { return bsFileStoreService.deleteByIdAndType(id,storeType)?Result.OK("删除成功"):Result.error("删除失败"); } /** * 批量删除 * * @param map * @return */ @AutoLog(value = "bs_file_store-批量删除") @ApiOperation(value="bs_file_store-批量删除", notes="bs_file_store-批量删除") @DeleteMapping(value = "/deleteBatch") public Result<?> deleteBatch(Map<String,String> map) { return bsFileStoreService.batchDeleteByIdAndType(map)?Result.OK("批量删除成功!"):Result.error("批量删除失败"); } }
2.service
@Service @DS("multi-datasource1") @Slf4j public class BsFileStoreServiceImpl extends ServiceImpl<BsFileStoreMapper, BsFileStore> implements IBsFileStoreService { @Autowired private BsFileStoreMapper bsFileStoreMapper; @Autowired private PmOsInfoMapper pmOsInfoMapper; @Autowired private PmLocalstoreInfoMapper pmLocalstoreInfoMapper; @Autowired private PmOsClustersMapper pmOsClustersMapper; @Autowired private PmOsBucketMapper pmOsBucketMapper; private final String LOCAL=StoreTypeEnum.LOCAL.getCode(); //loacl=2 private final String OSS=StoreTypeEnum.OSS.getCode();//oss=1 @Override @Transactional(rollbackFor = Exception.class) public boolean deleteByIdAndType(String id,String type){ if(OSS.equals(type)){ //01 获取存储名称osName String osName=pmOsInfoMapper.selectById(id).getOsName(); //02 桶删除(根据存储名称删除) LambdaQueryWrapper<PmOsBucket> bucketLambdaQueryWrapper=new LambdaQueryWrapper<>(); bucketLambdaQueryWrapper.eq(PmOsBucket::getOsName,osName); pmOsBucketMapper.delete(bucketLambdaQueryWrapper); //03 对象存储平台关系表删除 LambdaQueryWrapper<PmOsClusters> wrapper=new LambdaQueryWrapper<>(); wrapper.eq(PmOsClusters::getOsName,osName); pmOsClustersMapper.delete(wrapper); //04 对象存储表删除 pmOsInfoMapper.deleteById(id); } if(LOCAL.equals(type)){ pmLocalstoreInfoMapper.deleteById(id); } return true; } @Override public boolean batchDeleteByIdAndType(Map<String, String> map) { try { for (Map.Entry<String, String> entry : map.entrySet()) { deleteByIdAndType(entry.getKey(),entry.getValue() ); } } catch (Exception e) { log.error(e.getMessage()); throw new JeecgBootException("批量删除失败"); } return true; } }
3.postman模拟前端测试
http://127.0.0.1:7009/test/bsFileStore/deleteBatch
数据库表删除前:
数据库表删除后: