package com.hc.web.controller.browser.front;

import com.hc.business.model.OrderAttachment;
import com.hc.business.service.OrderAttachmentService;
import com.hc.core.utils.result.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;


/**
 * 线下汇款订单附件表(OrderAttachment)表控制层
 *
 * @author makejava
 * @since 2024-01-25 21:07:37
 */

@RestController
@RequestMapping("/new/api/front/orderAttachment")
public class FrontOrderAttachmentController {

    /**
     * 服务对象
     */
    private final OrderAttachmentService orderAttachmentService;

    public FrontOrderAttachmentController(OrderAttachmentService orderAttachmentService) {
        this.orderAttachmentService = orderAttachmentService;
    }


    @PostMapping("/insert")
    @ApiOperation(value = "新增附件", response = Result.class)
    public Result addOrderAttachment(@Valid @RequestBody List<OrderAttachment> orderAttachmentList) {
        for(OrderAttachment model:orderAttachmentList)
        {
            model.setCreateTime(System.currentTimeMillis());
        }
        orderAttachmentList.forEach(orderAttachmentService::insert);
        return Result.success(orderAttachmentList);
    }

    @GetMapping("/queryByOrderId")
    @ApiOperation(value = "查询订单下的所有附件", response = Result.class)
    public Result queryByOrderId(@RequestParam(defaultValue = "0") Integer orderId) {
        List<OrderAttachment> orderAttachments = orderAttachmentService.queryByOrderId(orderId);
        return Result.success(orderAttachments);
    }


}
