SettlementDiffController.java 2.16 KB
package vion.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.hutool.core.lang.Opt;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import vion.dto.SettlementDiffDTO;
import vion.model.FileInfo;
import vion.service.IFileService;
import vion.service.ISettlementDiffService;
import vion.vo.SettlementDiffVO;


@RestController
@RequestMapping("/api")
@RequiredArgsConstructor
public class SettlementDiffController {

    private final ISettlementDiffService settlementDiffService;
    private final IFileService fileService;

    @GetMapping("/settlementDiff/{no}")
    @SaCheckPermission(value = "settlementDiff:list", orRole = "admin")
    public Page<SettlementDiffVO> list(@PathVariable String no, SettlementDiffDTO dto) {
        return settlementDiffService.list(no, dto);
    }

    @GetMapping("/settlementDiff/{id}")
    public SettlementDiffVO getVOById(@PathVariable Long id) {
        return settlementDiffService.getVOById(id);
    }

    @PostMapping("/settlementDiff")
    @SaCheckPermission(value = "settlementDiff:save", orRole = "admin")
    public String save(@RequestBody SettlementDiffDTO dto) {
        return settlementDiffService.save(dto);
    }

    @PostMapping("/settlementDiff/{id}")
    @SaCheckPermission(value = "settlementDiff:edit", orRole = "admin")
    public String update(@PathVariable Long id, @RequestBody SettlementDiffDTO dto) {
        dto.setId(id);
        return settlementDiffService.update(id, dto);
    }

    @DeleteMapping("/settlementDiff/{id}")
    @SaCheckPermission(value = "settlementDiff:remove", orRole = "admin")
    @Transactional(rollbackFor = Exception.class)
    public String delById(@PathVariable Long id) {
        Opt.ofEmptyAble(fileService.lambdaQuery()
                        .eq(FileInfo::getSourceId, id)
                        .eq(FileInfo::getType, 15)
                        .list())
                .ifPresent(fileService::removeBatchByIds);
        return settlementDiffService.removeById(id) ? "删除成功" : "删除失败";
    }

}