package org.springblade.modules.system.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wn.common.datamodel.ResultDTO;
import io.swagger.annotations.Api;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.launch.constant.AppConstant;
import org.springblade.core.redis.cache.BladeRedis;
import org.springblade.core.secure.annotation.PreAuth;
import org.springblade.core.tenant.annotation.NonDS;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.constant.RoleConstant;
import org.springblade.modules.app.common.dto.WaybillDTO;
import org.springblade.modules.app.common.query.AdminWaybillQuery;
import org.springblade.modules.app.common.vo.ApprovalVO;
import org.springblade.modules.app.manager.WaybillManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@NonDS
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping(AppConstant.APPLICATION_SYSTEM_NAME + "/wayBill")
@PreAuth(RoleConstant.HAS_ROLE_ADMIN)
public class WayBillController extends BladeController {

    @Autowired
    private WaybillManager waybillManager;

    private final BladeRedis redis;

    //@ApiOperation(value = "分页查询调运单")
    @GetMapping("/page")
    public R<Page<WaybillDTO>> pageWaybill(AdminWaybillQuery waybillQuery) {
//        redis.set("test","123");
//        log.error("redis value is" + redis.get("test"));
        return R.data(waybillManager.pageWaybill(waybillQuery));
    }

    //@ApiOperation(value = "查询调运单详情", notes = "查询调运单详情")
    @GetMapping("/{id}")
    public R<WaybillDTO> getWaybillDetail(@PathVariable Long id) {
        return R.data(waybillManager.getAdminWaybillDetail(id));
    }

    //@ApiOperation(value = "审批调运单", notes = "审批调运单")
    @PostMapping("/approval")
    public R<Boolean> approvalWayBill(@RequestBody ApprovalVO approvalVO) {
        return R.data(waybillManager.approvalWaybillByBureau(approvalVO));
    }
}
