package com.jwipc.order.controller.pc;

import com.jwipc.order.constant.ModuleConst;
import com.jwipc.order.dto.DeliveryOrderControlSaveDTO;
import com.jwipc.order.logic.DeliveryOrderControlLogic;
import com.jwipc.order.model.query.DeliveryOrderControlQuery;
import com.jwipc.page.PageView;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * <p> 送货单管控相关页面相关接口</p>
 *
 * @author dengjsh
 * @version 1.0
 * @since JDK 1.8
 */

@Slf4j
@RestController
@RequestMapping(ModuleConst.MODULE_ROOT + "/deliveryOrderControl/rest")
@RequiredArgsConstructor
public class DeliveryOrderControlRestController {

    private final DeliveryOrderControlLogic deliveryOrderControlLogic;

    /**
     * 供应商送货单管控列表数据
     *
     * @param query 查询参数
     * @return
     */
    @GetMapping("list")
    public PageView list(DeliveryOrderControlQuery query) {
        return deliveryOrderControlLogic.getList(query);
    }

    /**
     * 保存&更新
     *
     * @param saveDTO 供应商送货单管控主数据
     * @throws Exception
     */
    @PostMapping("save")
    public ResponseEntity save(@RequestBody DeliveryOrderControlSaveDTO saveDTO) {
        deliveryOrderControlLogic.saveOrUpdate(saveDTO);
        return ResponseEntity.ok().build();
    }

    /**
     * 删除
     *
     * @param ids 要删除的ids
     * @return
     */
    @PostMapping("remove")
    public ResponseEntity remove(String ids) {
        List<String> idList = Arrays.asList(ids.split(","));
        deliveryOrderControlLogic.remove(idList);
        return ResponseEntity.ok().build();
    }

}
