ContractController.java 1.94 KB
package vion.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.github.linpeilie.Converter;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import vion.cron.ContractRunner;
import vion.dto.ContractDTO;
import vion.model.RContractStore;
import vion.service.IContractService;
import vion.service.IRContractStoreService;
import vion.vo.ContractVO;

import java.util.List;

/**
 * 合同管理
 */
@RestController
@RequestMapping("/api")
@RequiredArgsConstructor
public class ContractController {

    private final IContractService contractService;
    private final ContractRunner contractRunner;
    private final IRContractStoreService contractStoreService;
    private final Converter converter;

    @GetMapping("/contract")
    @SaCheckPermission(value = "contract:list", orRole="admin")
    public Page<ContractVO> list(ContractDTO dto) {
        return contractService.list(dto);
    }

    @GetMapping("/contract/{id}")
    @SaCheckPermission(value = "contract:query", orRole="admin")
    public ContractVO getById(@PathVariable Long id) {
        return converter.convert(contractService.getById(id), new ContractVO());
    }

    @PostMapping("/contract/{id}")
    @SaCheckPermission(value = "contract:edit", orRole="admin")
    public String updateById(@PathVariable Long id, ContractDTO dto) {
        return contractService.updateById(id, dto);
    }

    @PostMapping("/contract/store")
    @SaCheckPermission(value = "contract:store", orRole="admin")
    public String ss(List<RContractStore> contractStoreList) {
        return contractStoreService.saveBatch(contractStoreList) ? "更新成功" : "更新失败";
    }

    @PostMapping("/contractSync")
    @SaCheckPermission(value = "contract:sync", orRole="admin")
    public String manualSyncContract() {
        return contractRunner.contractSync() ? "成功" : "失败";
    }
}