DeliverLogController.java 1.83 KB
package vion.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import lombok.RequiredArgsConstructor;
import org.dromara.hutool.core.array.ArrayUtil;
import org.dromara.hutool.core.lang.Assert;
import org.springframework.web.bind.annotation.*;
import vion.dto.DeliverLogDTO;
import vion.service.IDeliverLogService;
import vion.vo.DeliverLogVO;

import java.util.List;
import java.util.Map;
import java.util.TreeMap;

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

    private final IDeliverLogService deliverLogService;

    @GetMapping
    @SaCheckPermission(value = "deliverLog:list", orRole = "admin")
    public Map<String, TreeMap<String, List<DeliverLogVO>>> list(DeliverLogDTO dto) {
        Assert.isTrue(ArrayUtil.isAllNotNull(dto.getLogDateStart(), dto.getLogDateEnd()), "查询时间范围不能为空");
        return deliverLogService.list(dto);
    }

    @GetMapping("/{id}")
    @SaCheckPermission(value = "deliverLog:query", orRole = "admin")
    public DeliverLogVO getById(@PathVariable Long id) {
        return deliverLogService.getById(id);
    }

    @PostMapping
    @SaCheckPermission(value = "deliverLog:save", orRole = "admin")
    public String save(@RequestBody List<DeliverLogDTO> deliverLogDTOList) {
        return deliverLogService.save(deliverLogDTOList);
    }

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

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

}