DeliveryRecordController.java 2.09 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.dto.DeliveryRecordDTO;
import vion.service.IDeliveryRecordService;
import vion.vo.DeliveryRecordVO;

import java.util.List;

/**
 * 发货记录管理
 */
@RestController
@RequestMapping("/api")
@RequiredArgsConstructor
public class DeliveryRecordController {

    private final IDeliveryRecordService deliveryRecordService;
    private final Converter converter;

    @GetMapping("/deliveryRecord")
    @SaCheckPermission(value = "deliveryRecord:list", orRole = "admin")
    public Page<DeliveryRecordVO> list(DeliveryRecordDTO dto) {
        return deliveryRecordService.list(dto);
    }

    @GetMapping("/deliveryRecord/{id}")
    @SaCheckPermission(value = "deliveryRecord:query", orRole = "admin")
    public DeliveryRecordVO getById(@PathVariable Long id) {
        return converter.convert(deliveryRecordService.getById(id), DeliveryRecordVO.class);
    }

    @PostMapping("/deliveryRecord")
    @SaCheckPermission(value = "deliveryRecord:save", orRole = "admin")
    public String save(DeliveryRecordDTO dto) {
        return deliveryRecordService.save(dto);
    }

    @PostMapping("/deliveryRecord/batch")
    @SaCheckPermission(value = "deliveryRecord:save", orRole = "admin")
    public String save(@RequestBody List<DeliveryRecordDTO> dto) {
        return deliveryRecordService.saveBatch(dto);
    }

    @PostMapping("/deliveryRecord/{id}")
    @SaCheckPermission(value = "deliveryRecord:edit", orRole = "admin")
    public String updateById(@PathVariable Long id, DeliveryRecordDTO dto) {
        dto.setId(id);
        return deliveryRecordService.updateById(dto);
    }

    @DeleteMapping("/deliveryRecord/{id}")
    @SaCheckPermission(value = "deliveryRecord:remove", orRole = "admin")
    public String delById(@PathVariable Long id) {
        return deliveryRecordService.removeById(id) ? "删除成功" : "删除失败";
    }

}