huliguo
3 天以前 11ec7ac8f4832c4274cf61a19cc35cda3de9e0e5
src/main/java/com/linghu/controller/PlatformController.java
@@ -3,8 +3,10 @@
import com.alibaba.excel.EasyExcel;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.linghu.mapper.ReferenceMapper;
import com.linghu.model.common.ResponseResult;
import com.linghu.model.entity.Platform;
import com.linghu.model.entity.Reference;
import com.linghu.model.entity.Type;
import com.linghu.model.excel.PlatformExcel;
import com.linghu.service.PlatformService;
@@ -38,6 +40,8 @@
    private PlatformService platformService;
    @Autowired
    private TypeService typeService;
    @Autowired
    private ReferenceMapper referenceMapper;
    @PostMapping
    @ApiOperation(value = "添加平台")
@@ -60,6 +64,11 @@
    @DeleteMapping("/{platformId}")
    @ApiOperation(value = "删除平台")
    public ResponseResult<Void> delete(@PathVariable Integer platformId) {
        //平台被引用了没
        Integer count = referenceMapper.selectCount(new LambdaQueryWrapper<Reference>().eq(Reference::getPlatform_id, platformId));
        if (count > 0) {
            return ResponseResult.error("该平台被引用中,不能删除");
        }
        boolean success = platformService.removeById(platformId);
        if (success) {
            return ResponseResult.success();
@@ -96,18 +105,15 @@
    }
    @GetMapping("/list")
    @ApiOperation("查询平台列表,不传页数和大小就查全部")
    public ResponseResult<List<Platform>> list(
            @RequestParam(required = false) Integer page,
            @RequestParam(required = false) Integer pageSize) {
        if (page != null && pageSize != null) {
    @ApiOperation("查询平台列表")
    public ResponseResult<Page<Platform>> list(
            @RequestParam(required = false,defaultValue = "1") Integer page,
            @RequestParam(required = false,defaultValue = "10") Integer pageSize) {
            Page<Platform> pageInfo = new Page<>(page, pageSize);
            Page<Platform> result = platformService.page(pageInfo);
            return ResponseResult.success(result.getRecords());
        } else {
            List<Platform> list = platformService.list();
            return ResponseResult.success(list);
        }
            return ResponseResult.success(result);
    }
    @GetMapping("/download")