package com.njzscloud.supervisory.order.controller;

import com.njzscloud.common.core.utils.R;
import com.njzscloud.common.mp.support.PageParam;
import com.njzscloud.common.mp.support.PageResult;
import com.njzscloud.common.security.support.UserDetail;
import com.njzscloud.common.security.util.SecurityUtil;
import com.njzscloud.supervisory.order.pojo.entity.OrderInfoEntity;
import com.njzscloud.supervisory.order.pojo.param.AuditOrderParam;
import com.njzscloud.supervisory.order.pojo.param.OrderPagingSearchParam;
import com.njzscloud.supervisory.order.pojo.result.OrderPagingResult;
import com.njzscloud.supervisory.order.service.OrderInfoService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Set;

/**
 * 订单信息
 */
@Slf4j
@RestController
@RequestMapping("/order_info")
@RequiredArgsConstructor
public class OrderInfoController {

    private final OrderInfoService orderInfoService;

    /**
     * 新增
     */
    @PostMapping("/add")
    public R<?> add(@RequestBody OrderInfoEntity orderInfoEntity) {
        orderInfoService.add(orderInfoEntity);
        return R.success();
    }

    /**
     * 修改
     */
    @PostMapping("/modify")
    public R<?> modify(@RequestBody OrderInfoEntity orderInfoEntity) {
        orderInfoService.modify(orderInfoEntity);
        return R.success();
    }

    /**
     * 删除
     */
    @PostMapping("/del")
    public R<?> del(@RequestBody List<Long> ids) {
        orderInfoService.del(ids);
        return R.success();
    }

    /**
     * 详情
     */
    @GetMapping("/detail")
    public R<OrderPagingResult> detail(@RequestParam Long id) {
        return R.success(orderInfoService.detail(id));
    }

    /**
     * 分页查询
     */
    @GetMapping("/paging")
    public R<PageResult<OrderPagingResult>> paging(PageParam pageParam, OrderPagingSearchParam orderPagingSearchParam) {
        return R.success(orderInfoService.paging(pageParam, orderPagingSearchParam));
    }

    /**
     * 审核分页查询
     */
    @GetMapping("/audit_paging")
    public R<PageResult<OrderPagingResult>> auditPaging(PageParam pageParam, OrderPagingSearchParam orderPagingSearchParam) {
        UserDetail userDetail = SecurityUtil.loginUser();
        Set<String> roles = userDetail.getRoles();
        return R.success(orderInfoService.auditPaging(pageParam, orderPagingSearchParam.setRoles(roles)));
    }

    /**
     * 审核
     */
    @GetMapping("/audit")
    public R<PageResult<OrderPagingResult>> audit(AuditOrderParam auditOrderParam) {
        orderInfoService.audit(auditOrderParam);
        return R.success();
    }

}
